Introduction to SQL Server
-
Upload
srinivasthiru -
Category
Documents
-
view
80 -
download
4
description
Transcript of Introduction to SQL Server
![Page 1: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/1.jpg)
Overview
What is SQL Server? Creating databases Administration Security Backup
![Page 2: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/2.jpg)
What is SQL Server?
Database management software Own file structure Own logins Own security
Access through 2 main ways: Query Analyzer Enterprise Manager
![Page 3: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/3.jpg)
What is SQL Server?
Consists of 2 Services: MSSQLServer
Data & query processing
SQL Server Agent Scheduled jobs & alerts
![Page 4: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/4.jpg)
Logging In
Windows NT Authentication
SQL Server Authentication
![Page 5: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/5.jpg)
Query Analyzer
Command-based interface Complete access to SQL Server Useful for creating scripts
![Page 6: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/6.jpg)
Enterprise Manager
Graphical User Interface Often more intuitive Easier to visualize
![Page 7: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/7.jpg)
Viewing Available Databases
Query Analyzer Execute sp_helpdb system stored
procedure
![Page 8: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/8.jpg)
Viewing Available Databases
Enterprise Manager Expand Databases
folder
![Page 9: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/9.jpg)
Creating a Database
Enterprise Manager Right-click
Database folder Select New
Database…
![Page 10: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/10.jpg)
Demonstration
Creating medical database
Set growth and file size options
![Page 11: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/11.jpg)
Transaction Log
Records data modifications Rolls forward completed transactions Rolls back incomplete transactions
![Page 12: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/12.jpg)
Data Types
At least 25 data types char, int, float uniqueidentifier, datetime, image
Can define own data types
![Page 13: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/13.jpg)
User-Defined Data Types
Based on existing data types Created with sp_addtype system
stored procedure
![Page 14: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/14.jpg)
Creating Tables
Query Analyzer
![Page 15: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/15.jpg)
Creating Tables
Enterprise Manager Right-click Tables Click New Table…
![Page 16: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/16.jpg)
Creating Tables
Enterprise Manager (cont.) Choose name
![Page 17: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/17.jpg)
Creating Tables
Enterprise Manager (cont.) Create columns
![Page 18: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/18.jpg)
Demonstration
Creating tables for medical database Product Patient Usage
![Page 19: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/19.jpg)
Constraints
Maintain data integrity Domain Integrity Entity Integrity Referential Integrity
![Page 20: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/20.jpg)
Constraints (cont.)
Primary Key Entity Integrity
Foreign Key Referential Integrity
CHECK Constraint Domain Integrity
![Page 21: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/21.jpg)
Add Primary Key
Query Analyzer
![Page 22: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/22.jpg)
Add Primary Key
Enterprise Manager Right-click column of interest Set Primary Key
![Page 23: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/23.jpg)
Add Foreign Keys
Query Analyzer
![Page 24: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/24.jpg)
Add CHECK
Query Analyzer
![Page 25: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/25.jpg)
View Constraints
Query Analyzer Execute sp_helpconstraint
system stored procedure
![Page 26: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/26.jpg)
Rules
Specify allowed values for columns Example
Allowed states: PA, WV, OH
![Page 27: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/27.jpg)
Creating Rules
Query Analyzer Create rule with CREATE RULE statement Bind rule with sp_bindrule system stored
procedure Unbind with sp_unbindrule
![Page 28: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/28.jpg)
Create Rules
Enterprise Manager Input only rule
name and definition
![Page 29: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/29.jpg)
Create Rules
Enterprise Manager (cont.) Bind rule
Open rule properties
![Page 30: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/30.jpg)
Creating Rules
Enterprise Manager (cont.) Bind Rule (cont.)
Click Bind Columns… on Rule Properties
Select table and column
![Page 31: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/31.jpg)
Inserting Data
Query Analyzer Use INSERT
statement
![Page 32: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/32.jpg)
Inserting Data
Enterprise Manager Right-click table name Select Open Table ► Return all rows
![Page 33: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/33.jpg)
Inserting Data
Enterprise Manager (cont.) Type values as needed
![Page 34: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/34.jpg)
Stored Procedures
Collection of SQL statements Can accept variables Can be used for security
Users can be granted right to use stored procedure, even if they do not have access to underlying tables
![Page 35: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/35.jpg)
Creating Stored Procedures
Query Analyzer Use CREATE PROCEDURE statement Define variables as @variable_name
![Page 36: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/36.jpg)
Using Stored Procedures
Use EXEC procedure_name Pass values by reference or position
![Page 37: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/37.jpg)
Transactions
Process statements as a group Must be committed
“All-or-nothing” – All statements are committed or none are
If interrupted, transaction is rolled back automatically
![Page 38: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/38.jpg)
Transactions
Query Analyzer Use BEGIN TRANSACTION and
COMMIT TRANSACTION statements Use ROLLBACK TRANSACTION to
cancel
![Page 39: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/39.jpg)
Transaction Example
Committed transaction Rolled back transaction Interrupted transaction
![Page 40: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/40.jpg)
Views
Specify how data is seen Focus data Security
Grant permissions on Views
![Page 41: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/41.jpg)
Creating Views
Query Analyzer Use CREATE VIEW statement
![Page 42: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/42.jpg)
Creating Views
Enterprise Manager Add tables
![Page 43: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/43.jpg)
Views
Enterprise Manager (cont.) Select column
names Enter Aliases
![Page 44: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/44.jpg)
Security
User Management Roles Logins Users
Program Security
![Page 45: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/45.jpg)
Roles
Operations that members of role can perform
Users are assigned roles
![Page 46: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/46.jpg)
Creating Roles
Type Role name Select Standard
Role
![Page 47: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/47.jpg)
Creating Roles
Open Role properties
Click Permissions button
![Page 48: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/48.jpg)
Creating Roles
Set allowed actions Table actions Allowed Views Allowed Stored
Procedures
![Page 49: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/49.jpg)
Logins
Allow users to log in to SQL Server
Defined under Security folder
![Page 50: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/50.jpg)
Creating Logins
Input Login name Set password Set defaults
![Page 51: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/51.jpg)
Creating Logins
Choose allowed databases
Select Roles
![Page 52: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/52.jpg)
Users
Who is allowed to access database
Role user has
![Page 53: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/53.jpg)
Setting Users
Only necessary if you did not set during login creation
![Page 54: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/54.jpg)
Program Security
SQL Server Home Page http://www.microsoft.com/sql
News, tips, & tools
![Page 55: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/55.jpg)
Program Security
Microsoft Baseline Security Analyzer (MBSA) Runs under Windows 2000 or XP Checks program settings & security
patches Useful for many Microsoft programs,
including SQL Server 7.0 and 2000
![Page 56: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/56.jpg)
Program Security
MBSA can be downloaded at: http://www.microsoft.com/technet/treeview/default.asp
?url=/technet/security/tools/Tools/mbsahome.asp
![Page 57: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/57.jpg)
Backup
Create Backup Device Container for your database
Schedule Backup jobs
![Page 58: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/58.jpg)
Creating a Backup Device
Enterprise Manager Look under
Management folder
![Page 59: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/59.jpg)
Creating a Backup Device
Enterprise Manager (cont.) Set name Set location
![Page 60: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/60.jpg)
Backing Up
Back up and restore from Databases folder
![Page 61: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/61.jpg)
Backing Up
Select your backup device as the Destination
Set a schedule if desired
![Page 62: Introduction to SQL Server](https://reader033.fdocuments.us/reader033/viewer/2022061200/547715f5b4af9f7b108b4609/html5/thumbnails/62.jpg)
Check Jobs
Check backup jobs under SQL Server Agent under the Management folder