62
Overview What is SQL Server? Creating databases Administration Security Backup

Introduction to SQL Server

Embed Size (px)

DESCRIPTION

Introduction to SQL Server 2008

Citation preview

Page 1: Introduction to SQL Server

Overview

What is SQL Server? Creating databases Administration Security Backup

Page 2: Introduction to SQL Server

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

What is SQL Server?

Consists of 2 Services: MSSQLServer

Data & query processing

SQL Server Agent Scheduled jobs & alerts

Page 4: Introduction to SQL Server

Logging In

Windows NT Authentication

SQL Server Authentication

Page 5: Introduction to SQL Server

Query Analyzer

Command-based interface Complete access to SQL Server Useful for creating scripts

Page 6: Introduction to SQL Server

Enterprise Manager

Graphical User Interface Often more intuitive Easier to visualize

Page 7: Introduction to SQL Server

Viewing Available Databases

Query Analyzer Execute sp_helpdb system stored

procedure

Page 8: Introduction to SQL Server

Viewing Available Databases

Enterprise Manager Expand Databases

folder

Page 9: Introduction to SQL Server

Creating a Database

Enterprise Manager Right-click

Database folder Select New

Database…

Page 10: Introduction to SQL Server

Demonstration

Creating medical database

Set growth and file size options

Page 11: Introduction to SQL Server

Transaction Log

Records data modifications Rolls forward completed transactions Rolls back incomplete transactions

Page 12: Introduction to SQL Server

Data Types

At least 25 data types char, int, float uniqueidentifier, datetime, image

Can define own data types

Page 13: Introduction to SQL Server

User-Defined Data Types

Based on existing data types Created with sp_addtype system

stored procedure

Page 14: Introduction to SQL Server

Creating Tables

Query Analyzer

Page 15: Introduction to SQL Server

Creating Tables

Enterprise Manager Right-click Tables Click New Table…

Page 16: Introduction to SQL Server

Creating Tables

Enterprise Manager (cont.) Choose name

Page 17: Introduction to SQL Server

Creating Tables

Enterprise Manager (cont.) Create columns

Page 18: Introduction to SQL Server

Demonstration

Creating tables for medical database Product Patient Usage

Page 19: Introduction to SQL Server

Constraints

Maintain data integrity Domain Integrity Entity Integrity Referential Integrity

Page 20: Introduction to SQL Server

Constraints (cont.)

Primary Key Entity Integrity

Foreign Key Referential Integrity

CHECK Constraint Domain Integrity

Page 21: Introduction to SQL Server

Add Primary Key

Query Analyzer

Page 22: Introduction to SQL Server

Add Primary Key

Enterprise Manager Right-click column of interest Set Primary Key

Page 23: Introduction to SQL Server

Add Foreign Keys

Query Analyzer

Page 24: Introduction to SQL Server

Add CHECK

Query Analyzer

Page 25: Introduction to SQL Server

View Constraints

Query Analyzer Execute sp_helpconstraint

system stored procedure

Page 26: Introduction to SQL Server

Rules

Specify allowed values for columns Example

Allowed states: PA, WV, OH

Page 27: Introduction to SQL Server

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

Create Rules

Enterprise Manager Input only rule

name and definition

Page 29: Introduction to SQL Server

Create Rules

Enterprise Manager (cont.) Bind rule

Open rule properties

Page 30: Introduction to SQL Server

Creating Rules

Enterprise Manager (cont.) Bind Rule (cont.)

Click Bind Columns… on Rule Properties

Select table and column

Page 31: Introduction to SQL Server

Inserting Data

Query Analyzer Use INSERT

statement

Page 32: Introduction to SQL Server

Inserting Data

Enterprise Manager Right-click table name Select Open Table ► Return all rows

Page 33: Introduction to SQL Server

Inserting Data

Enterprise Manager (cont.) Type values as needed

Page 34: Introduction to SQL Server

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

Creating Stored Procedures

Query Analyzer Use CREATE PROCEDURE statement Define variables as @variable_name

Page 36: Introduction to SQL Server

Using Stored Procedures

Use EXEC procedure_name Pass values by reference or position

Page 37: Introduction to SQL Server

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

Transactions

Query Analyzer Use BEGIN TRANSACTION and

COMMIT TRANSACTION statements Use ROLLBACK TRANSACTION to

cancel

Page 39: Introduction to SQL Server

Transaction Example

Committed transaction Rolled back transaction Interrupted transaction

Page 40: Introduction to SQL Server

Views

Specify how data is seen Focus data Security

Grant permissions on Views

Page 41: Introduction to SQL Server

Creating Views

Query Analyzer Use CREATE VIEW statement

Page 42: Introduction to SQL Server

Creating Views

Enterprise Manager Add tables

Page 43: Introduction to SQL Server

Views

Enterprise Manager (cont.) Select column

names Enter Aliases

Page 44: Introduction to SQL Server

Security

User Management Roles Logins Users

Program Security

Page 45: Introduction to SQL Server

Roles

Operations that members of role can perform

Users are assigned roles

Page 46: Introduction to SQL Server

Creating Roles

Type Role name Select Standard

Role

Page 47: Introduction to SQL Server

Creating Roles

Open Role properties

Click Permissions button

Page 48: Introduction to SQL Server

Creating Roles

Set allowed actions Table actions Allowed Views Allowed Stored

Procedures

Page 49: Introduction to SQL Server

Logins

Allow users to log in to SQL Server

Defined under Security folder

Page 50: Introduction to SQL Server

Creating Logins

Input Login name Set password Set defaults

Page 51: Introduction to SQL Server

Creating Logins

Choose allowed databases

Select Roles

Page 52: Introduction to SQL Server

Users

Who is allowed to access database

Role user has

Page 53: Introduction to SQL Server

Setting Users

Only necessary if you did not set during login creation

Page 54: Introduction to SQL Server

Program Security

SQL Server Home Page http://www.microsoft.com/sql

News, tips, & tools

Page 55: Introduction to SQL Server

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

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

Backup

Create Backup Device Container for your database

Schedule Backup jobs

Page 58: Introduction to SQL Server

Creating a Backup Device

Enterprise Manager Look under

Management folder

Page 59: Introduction to SQL Server

Creating a Backup Device

Enterprise Manager (cont.) Set name Set location

Page 60: Introduction to SQL Server

Backing Up

Back up and restore from Databases folder

Page 61: Introduction to SQL Server

Backing Up

Select your backup device as the Destination

Set a schedule if desired

Page 62: Introduction to SQL Server

Check Jobs

Check backup jobs under SQL Server Agent under the Management folder