sql server database administration and design server database administration and design.pdfsql...

Post on 15-Oct-2020

19 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

1  

SQL Server Database Administration and Design By Dave Peru, October 2011

Introduction Name Handout Sheet Developer’s Perspective - Story Outline Create a Database Create a New Data Model Data Model Diagrams Relationships and Indexes SQL Server Account Security

SQL Scripts Moving Database Files Create Web Pages for Editing Database CSS Files and Data Entry Forms Database Backups SQL Server Agent

2  

Create a Database

Launch SQL Server Management Studio

Enter MyDatabase, click OK:

3  

Right click over Tables, select New Table from the popup menu:

Create Table1:

Set Primary Key:

Save Table 1 :

Close workspace windows, <ctrl-f4>, <ctrl-f4>

4  

Right click over Tables, select New Table from the popup menu:

Create Table 2:

Save Table 2 :

Close workspace windows, <ctrl-f4> Expand Tables folder:

5  

Create a New Data Model Expand Database Diagrams folder:

Click Yes. Right click over Database Diagrams folder, add new diagram:

Select both tables, click Add:

Click Close, position tables, change view:

6  

Change view on Table 2, your diagram should look like the following:

Database Relationships

Graphical user interfaces and hidden handshakes:

Click OK, OK, adjust relationship object:

Reason for Relationships, Software Service Providers, Amazon S3, lost data

VoltDB – massively large distributed databases with relationship integrity

Lost data, Jay from J & J Story

7  

Database Indexes – Increase Speed

Data Model Diagrams Right click over the spot, select menu item:

Click Add:

Click Close, Click :

Then click Yes:

8  

Printing Data Model Diagrams

Print Problems, Select Copy Diagram to Clipboard:

Launch Word, expand margins, paste:

Show Buzz diagram:

9  

SQL Server Account Security

Expand Security folder in Object Explorer, right click over Logins, New Login:

Fill out the form for “user1”:

Click OK to continue.

10  

Right click Users folder under Security under MyDatabase:

Click on the eclipses:

Enter “user1”, click on the “Check Names” button, then click OK:

File out “user1” for the User name field, then click on OK again:

11  

Expand the Schemas folder, right click over “dbo” and select “Properties” menu:

Go to the “Permissions” tab:

Click on the “Add” button, enter “user1”, click “Check Names”, click OK:

Select the access rights as follows and click OK:

12  

Working with SQL Scripts, Start in MyDatabase / Security / Users

You should see the following:

Select File Save As menu:

Create new directory “c:\demo1\sql”:

13  

From MyDatabase Security Logins, script to clipboard the following:

You will see the following:

Click on the button to run the script. You should see the following result:

Recreate “user1” access to database:

14  

Select Script Action To Clipboard:

Paste into our script file:

Add “user1” as user of “MyDatabase”, script to clipboard, paste into script:

Right click over “dbo”, select “Properties” from popup menu:

Select access rights, script to clipboard:

15  

Paste into our script file. Click on the button to run the script. You should see the following result:

Verify user1 exists and has the correct access rights:

Moving Database Files

Good Object Oriented Design for Code and Data

Detach Database

16  

Find database files, and cut to clipboard:

Navigate to “c:\demo1”, create “Database Files” folder, paste files to new location:

Return to SQL Server Management Studio

17  

Attach Database:

Navigate to “c:\demo1\Database Files” and select MDB file:

Database is back, but user1 account is now invalid, run our script:

18  

Select “c:\demo1\sql\ DropCreateUser1.sql”:

Exit SQL Server Management Studio Create Web Pages for Editing Our Database Launch Visual Studio:

Select New / Web Site… menu item:

Select “c:\demo1\website1” for the location, then click OK:

19  

Create a new solutions file for project settings. Select the solution root inside Solution Explorer:

Next, select file Save As menu item:

20  

In the “c:\demo1\sln” folder, save the website1.sln file:

Time to prepare to run a program generator called Mintiera.

Mintiera will create web pages we can use to edit records in our database.

Delete App_Data folder:

Delete “Default.aspx” file:

21  

Use Visual Studio Import Feature. Create App_Code folder:

Create “Admin” folder:

Create “css” folder. Create “Javascript” folder. You should see the following:

22  

Mintiera web site:

Mintiera is code generator: Web pages, CSS friendly user controls, middle tier data access components, for editing records in a database

The way Mintiera works: 10 SQL data types cross 20 code snippets for CRUD

Northwind Data Model:

Editing the Northwind data base:

23  

Running Mintiera on MyDatabase:

Click on “Aready Registered, Login” link:

Mintiera uses Click-Once deployment, click button to launch program:

Enter Connection Parameters and click Next button:

Use defaults for Layer Options, click Next button:

24  

Copy Connection String text into clipboard:

Return to Visual Studio. Edit web.config file:

Return to Mintiera, select Table1 and click Next button:

25  

Default values for SQL field types determined from data model. Use defaults, click Next:

Default values key generation method determined by field type, click Next button:

26  

Default values for related tables taken from data model, click Next button:

Mintiera supports 4 levels of data validation: Client-Side Javascript, web page presentation layer, middle tier data access component, and database validation. Default values for related tables taken from data model, click Next button:

27  

You must specify a temporary folder for output (c:\tmp shown below):

Click Generate Code button to create about 4000 lines of code:

28  

Click Restart button and select Table2, click Next button:

Use Mintiera defaults for Field Types and options, click Next button:

29  

Select the following for Table2 Primary and Foreign Key Settings, click Next:

Use Mintiera defaults for related tables, click Next:

Use defaults for Validation Settings, click next button:

30  

Click “Generate Code” button for Output Settings:

Click “Exit” button when code generation is complete:

31  

Next, we need to import the generated Mintiera code into our Visual Studio project. Right click over Admin folder in Solution Explorer, and select Add Existing Item:

Select all the files in “c:\tmp\WebForms2” as shown:

We just added all the web pages we need to edit MyDatabase.

32  

Right click over the “App_Code” folder, select Add Existing Items…” from the popup:

Select all the files in “c:\tmp\App_code” folder to import all the middle tier data access components:

Again, right click over the “App_Code” folder, select Add Existing Items…” from the popup. And import all the App_Code_Support_Classes to Visual Studio:

33  

Right click over the “css” folder, select Add Existing Items…” from the popup:

Import all the files from “c:\tmp\css”:

Right click over the “Javascript” folder, select Add Existing Items…” from the popup:

34  

Import all the files from “c:\tmp\Javascript”:

Right click over the root folder, select Add Existing Items…” from the popup:

Import all the files from “c:\tmp\ GlobalApplicationCode”:

Add a reference to System.Design:

35  

Select Build Solution from the Build menu:

Confirm Build succeeded:

Return to SQL Server Management Studio. Select File / Open / File menu:

36  

Table1Script.sql and Table2Script.sql contain SQL script for stored procedures used by middle tier data access components for doing CRUD operations.

Navigate to “c:\tmp\sql”, select all files, click on the Open button:

Click <F5> to execute:

Click <F4> to close the window, click <F5> to execute the next SQL script:

37  

Click <F4> to close the window, exit the management studio, return to Visual Studio.

Set MyDatabase.aspx as the start page for Visual Studio.

Hit <ctrl-F5> to launch brower:

Show web pages for editing records.

38  

CSS Files and Data Entry Forms

Mintiera uses a table-less web page design for page layout. No HTML-table tags.

Table tags auto fill versus div-tag liquid fill.

This OuterDiv-InnerDiv CSS method works with the following browsers (no hacks):

IE 6, IE 7, IE 8 regular mode, IE 8 compatibility mode

Firefox 3, Opera 9, Safari 3, and Google Chrome 4

The method uses only CSS to control layout. Content is separated from presentation.

Remove the CSS file and you see the following:

CSS friendly controls can be modified for data entry forms.

Restore CSS files and layout returns:

39  

The idea of separating content from presentation is illustrated by CSSZenGarden.Com

Database Backups

40  

Remove default backup file:

Click on Add button, select file and location, click on OK button:

Click on the Options button, select Overwrite all existing backup sets, Click OK:

41  

Once completed, you will see the following:

SQL Server Agent

Start SQL Server Agent if not running:

42  

Script database backup to clipboard:

Create new SQL Server Agent Job:

Fill out Name, then click on Step:

43  

Click on New button below:

File out Step 1 and click OK:

Click on Schedules, click on New, fill out form, then click OK:

44  

Job is now ready:

Click OK to complete. Test job:

Job completed ok:

top related