SQL Server Basics
SQL Server Basics
for non-DBAs
Anil Desai
Speaker Information
• Anil Desai
– Independent consultant (Austin, TX)
– Author of several SQL Server books
– Instructor, “Implementing and Managing SQL
Server 2005” (Keystone Learning)
– Info: http://AnilDesai.net or Anil@AnilDesai.net
Overview and Agenda
I. SQL Server 2005 Platform Overview
• Best practices:
– Monitor and analyze real-world workloads
– Separate data files and transaction log files
Comparing RAID Levels
RAID Level RAID Description Disk Space Cost Read Performance Write Performance
RAID 5 Stripe Set with Parity Equivalent to the size Increased Decreased
of one disk in the
array.
• Backup operations
– Full Backups
– Differential Backups
– Transaction Log Backups
• Allows point-in-time recovery
Recovery Processes
• Recovery process:
– Latest full backup (Required)
– Latest differential backup (Optional)
– Unbroken sequence of transaction log backups
(Optional)
• (from
Microsoft
SQL Server
2005 Books
Online)
Security Best Practices
• Make security a part of your standard process
• Use the principle of least privilege
• Implement defense-in-depth (layered security)
• Enable only required services and features
• Regularly review security settings
• Educate users about the importance of
security
• Define security roles based on business rules
SQL Server Service Accounts
• Local Service Account
– Permissions of “Users” group (limited)
– No network authentication
• Network Service Account
– Permissions of Users group
– Network authentication with Computer account
• Domain User Accounts
– Adds network access for cross-server functionality
SQL Server Surface Area
Configuration
• Default installation: Minimal services
• SAC for Services and Connections
– Allow Remote Connections
– Access to Reporting Services, SSIS, etc.
• SAC for Features
– Remote queries
– .NET CLR Integration
– Database Mail
– xp_cmdshell
Managing Logins
• Windows Logins
– Authentication/Policy managed by Windows
• Database Roles
– Users can belong to multiple roles
– Guest (does not require a user account)
– dbo (Server sysadmin users)
• Application Roles
– Used to support application code
Creating Database Users and
Roles
• CREATE USER
– Replaces sp_AddUser and sp_GrantDBAccess
– Can specify a default schema
– Managed with ALTER USER and DROP USER
• CREATE ROLE
– Default owner is creator of the role
• SQL Server Management Studio
– Working with Users and Roles
Built-In Server / Database Roles
Understanding Database
Schemas
• Schemas
– Logical collection of related database objects
– Part of full object name:
• Server.Database.Schema.Object
– Default schema is “dbo”
• Managing Schemas
– CREATE, ALTER, DROP SCHEMA
– SQL Server Management Studio
– Can assign default schemes to database users:
• WITH DEFAULT_SCHEMA ‘SchemaName’
Configuring Permissions
• Scopes of Securables
– Server
– Database
– Schema
– Objects
• Permission Settings:
– GRANT
– REVOKE
– DENY
• Options
– WITH GRANT OPTION
– AS (Sets permissions using another user or role)
Managing Execution
Permissions
• Transact-SQL Code can run under a specific
execution context
– By default, will execute as the caller
• EXECUTE AS clause:
– Defined when creating an object or procedure
– Options:
• CALLER (Default)
• SELF: Object creator
• Specified database username
Other Security Options
• Database Encryption
– Encrypting Object Definitions
– Data encryption
• SQL Server Agent
– Proxies based on subsystems allow lock-
down by job step types
• Preventing SQL Injection attacks
– Use application design best practices
Managing Database Objects
• Non-Clustered Index
– Physical data structures that facilitate data retrieval
– Can have many indexes
– Indexes may include many columns
Database Management
Best Practices
Maintenance and optimization of
SQL Server 2005
SQL Server Maintenance
• Monitor real-world (production) database
usage
• Communicate and coordinate with application
developers and users
• Develop policies and roles for database
administration
• Optimize database administration
– Automate common operations
– Generate scripts for routine maintenance
SQL Server Maintenance
• Regular tasks
– Monitor disk space usage
– Monitor application performance
– Monitor physical and logical disk space
– Maintain indexes and data files
– Review backup and recovery operations
– Review security
– Review SQL Server Logs and/or Windows logs
– Verify the status of all jobs
SQL Server Management Features
• SQL Server Agent
– Jobs
– Alerts
– Operators
• SQL Server Logs
• Database Mail
• Linked Servers
For More Information
• www.microsoft.com/sql
• Resources from Anil Desai
– Web Site (http://AnilDesai.net)
– E-Mail: Anil@AnilDesai.net
• Keystone Learning Course: “Microsoft
SQL Server 2005: Implementation and
Maintenance (Exam 70-431)”
• The Rational Guide to Managing
Microsoft Virtual Server 2005
• The Rational Guide to Scripting Microsoft
Virtual Server 2005
Questions & Discussion