sql server database administration and design server database administration and design.pdfsql...
TRANSCRIPT
![Page 1: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/1.jpg)
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
![Page 2: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/2.jpg)
2
Create a Database
Launch SQL Server Management Studio
Enter MyDatabase, click OK:
![Page 3: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/3.jpg)
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>
![Page 4: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/4.jpg)
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:
![Page 5: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/5.jpg)
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:
![Page 6: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/6.jpg)
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
![Page 7: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/7.jpg)
7
Database Indexes – Increase Speed
Data Model Diagrams Right click over the spot, select menu item:
Click Add:
Click Close, Click :
Then click Yes:
![Page 8: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/8.jpg)
8
Printing Data Model Diagrams
Print Problems, Select Copy Diagram to Clipboard:
Launch Word, expand margins, paste:
Show Buzz diagram:
![Page 9: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/9.jpg)
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.
![Page 10: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/10.jpg)
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:
![Page 11: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/11.jpg)
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:
![Page 12: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/12.jpg)
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”:
![Page 13: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/13.jpg)
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:
![Page 14: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/14.jpg)
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:
![Page 15: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/15.jpg)
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
![Page 16: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/16.jpg)
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
![Page 17: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/17.jpg)
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:
![Page 18: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/18.jpg)
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:
![Page 19: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/19.jpg)
19
Create a new solutions file for project settings. Select the solution root inside Solution Explorer:
Next, select file Save As menu item:
![Page 20: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/20.jpg)
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:
![Page 21: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/21.jpg)
21
Use Visual Studio Import Feature. Create App_Code folder:
Create “Admin” folder:
Create “css” folder. Create “Javascript” folder. You should see the following:
![Page 22: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/22.jpg)
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:
![Page 23: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/23.jpg)
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:
![Page 24: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/24.jpg)
24
Copy Connection String text into clipboard:
Return to Visual Studio. Edit web.config file:
Return to Mintiera, select Table1 and click Next button:
![Page 25: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/25.jpg)
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:
![Page 26: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/26.jpg)
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:
![Page 27: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/27.jpg)
27
You must specify a temporary folder for output (c:\tmp shown below):
Click Generate Code button to create about 4000 lines of code:
![Page 28: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/28.jpg)
28
Click Restart button and select Table2, click Next button:
Use Mintiera defaults for Field Types and options, click Next button:
![Page 29: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/29.jpg)
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:
![Page 30: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/30.jpg)
30
Click “Generate Code” button for Output Settings:
Click “Exit” button when code generation is complete:
![Page 31: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/31.jpg)
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.
![Page 32: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/32.jpg)
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:
![Page 33: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/33.jpg)
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:
![Page 34: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/34.jpg)
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:
![Page 35: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/35.jpg)
35
Select Build Solution from the Build menu:
Confirm Build succeeded:
Return to SQL Server Management Studio. Select File / Open / File menu:
![Page 36: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/36.jpg)
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:
![Page 37: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/37.jpg)
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.
![Page 38: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/38.jpg)
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:
![Page 39: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/39.jpg)
39
The idea of separating content from presentation is illustrated by CSSZenGarden.Com
Database Backups
![Page 40: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/40.jpg)
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:
![Page 41: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/41.jpg)
41
Once completed, you will see the following:
SQL Server Agent
Start SQL Server Agent if not running:
![Page 42: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/42.jpg)
42
Script database backup to clipboard:
Create new SQL Server Agent Job:
Fill out Name, then click on Step:
![Page 43: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/43.jpg)
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:
![Page 44: SQL Server Database Administration and Design Server Database Administration and Design.pdfSQL Server Agent . 2 ... Working with SQL Scripts, Start in MyDatabase / Security / Users](https://reader033.vdocument.in/reader033/viewer/2022052500/6050f40e700b32041f3a6f06/html5/thumbnails/44.jpg)
44
Job is now ready:
Click OK to complete. Test job:
Job completed ok: