SQL Complete Notes
SQL Complete Notes
shahar@valinor.co.il
http://www.valinor.co.il
This Seminar agenda
Let’s Go!
Relational Database Server Goals
Enterprise
Standard
Workgroup
Web
express Datacenter
Parallel Data Warehouse
compact Read more at:
http://www.microsoft.com/sqlserver/2008/en/us/editions.aspx
SQL Server Architecture
• Instance-Specific • Instance-unaware
(one service per instance): Notification Services
SQL Server Integration Services
SQL Server Agent (SSIS)
Analysis Services SQL Server Browser
(SSAS) SQL Server Active
Reporting Services Directory Helper
(SSRS) SQL Writer
Full-Text Search (iFTS)
SQL Server install – best practices
Database storage
Primarily table data and index data
Database Files:
Primary data file (*.mdf)
Secondary data files (*.ndf)
Transaction log file(s) (*.ldf)
Filegroups:
Logical collections of files
Objects can be created on filegroups
Physical DB Structure
Data file:
.mdf or .ndf
Log file:
.ldf
Extent: 8 contagious
pages – 64K
Page: 8KB
The Transaction Log
1 Data modification is
sent by application
3 Modification is recorded
Buffer Cache in transaction log on disk
Disk
No log backups.
Automatically reclaims log space to keep space
requirements small, essentially eliminating the
need to manage the transaction log space.
Changes since the most recent backup are
unprotected. In the event of a disaster, those
changes must be redone.
Can recover only to the end of a backup.
Full Recovery Model
No
Notify operator
Job step 3: Custom Yes
Fail?
Application (ActiveX Script)
No
Notify operator
What Is the Job Activity Monitor?
Backup / Restore
Attaching and detaching databases
Allows directly copying data/log files
Database must be taken offline
Copy Database Wizard
Other methods:
SQL Server Integration Services (SSIS)
Generating scripts for database objects
Bulk copy / BULK INSERT
SQL Logs
• SysAdmin • db_accessadmin
• ServerAdmin • db_BackupOperation
• SetupAdmin • db_DataReader
• SecurityAdmin • db_DataWriter
• ProcessAdmin • db_DDLAdmin
• DiskAdmin • db_DenyDataReader
• DBCreator • db_DenyDataWriter
• BulkAdmin • db_Owner
• db_SecurityAdmin
• public
Security Best Practices
objects
Scheme
Database
users\roles
Server logins
Domain users
SQL Server High Availability Options
Database Mirroring
Log-shipping
SQL Server Fail-Over Clusters
Geo-Cluster
Replication
Load-Balancing (at network or OS level)
SQL Server hierarchy
Server
Server
Server
Server Server
Server
Server
Server Server
What Are Schemas?
Person
Contact
(Server1.AdventureWorks.Person.Contact)
Sales
Customer
(Server1.AdventureWorks.Sales.Customer)
dbo
ErrorLog AdventureWorks
(Server1.AdventureWorks.dbo.ErrorLog)
Overview of Database Objects
Index Considerations
Can dramatically increase query performance
Adds overhead for index maintenance
Best Practices
Base design on real-world workloads
SQL Profiler; Execution Plans
Scenarios:
Retrieving ranges of data
Retrieving specific values
Index Types
Clustered index
Controls the physical order of rows
Does not require additional disk space
One per table (may inc. multiple columns)
Non-Clustered Index
Physical data structures that facilitate data retrieval
Can have many indexes
Indexes may include many columns