SQL Overview

advertisement
And Franchise Colleges
HSQ - DATABASES & SQL
2
MS SQL Server Overview
By MANSHA NAWAZ
Section 2
MS SQL Overview
1
OVERVIEW
Section 2
•
Client Server Architecture
•
What is SQL?
•
MS SQL Server V MS Access
•
Creating an SQL Server Database
•
Enterprise Manager Example
•
SQL Enterprise Manager Resources
•
Query Analyzer Example
•
SQL in Query Analyzer
•
SQL Query Analyser Resources
•
Additional SQL Resources
MS SQL Overview
2
Client/Server Architecture
•
•
•
Server provides services for the Clients which are responsible for interacting with
the users (Input/Output)
Server is responsible for performing a service (e.g. transaction) and guaranteeing
the integrity of the data
Well suited for distributed systems handling large amounts of data
User Workstation
Department
File-Servers
Corporate
Servers
User Workstation
Operator
Workstation
Section 2
MS SQL Overview
3
Database Development
Systems Analysis & Design
DFD DataStores, DataFlows and Data Dictionary
DATA MODEL
TABLE SET
E-R Model
NF
Database Management System (DBMS)
PHYSICAL VIEW OF DATA
LOGICAL VIEW OF DATA
TABLES (computer view))
FORMS (user view)
WEB DEVELOPMENT
CLIENT DB Development
Database connectivity via websites
www .net technology
Macromedia Dreamweaver
MS Visual Studio
Database connectivity via
desktop DBMS such as
MS Access
Client Area of Interest
Section 2
Program Development
Database connectivity via
programming languages
such as MS Visual Basic
Server Area of Interest
MS SQL Overview
4
What is SQL?
•
•
•
•
Structured Query Language
It is the standard language for managing a database
• Creating,
• Accessing
• Searching
• Modifying
Many different Systems depending on maker of software:
• Oracle
• Microsoft SQL Server
• MS Access
• Sybase etc.
Initially we will examine SQL under MS Access Some Variations in symbols
– non-standard SQL
•
In the main we use MS SQL Server 2000
– standard SQL
Section 2
MS SQL Overview
ACCESS
“
#
SQL
‘
%
5
MS SQL Server
V
MS Access
•
MS Access is
Desktop based
•
Small, low-traffic
database
systems
•
MS SQL Server is a server based database.
•
Multi User – Multi Platform Systems
•
Large, high volume traffic database systems
•
Server holds database. Workstation provides access.
•
For web or database systems if the access traffic is likely to
generate more than 20 concurrent database hits at a time,
•
it's time to move to a database server
•
Generally, database servers like MS SQL Server are the way
to go for database or web/database systems
•
Many and wide ranging user base for system
•
Additional Security and Login features
•
MySQL (free sql database used for connectivity to Websites via
PHP).
Section 2
MS SQL Overview
•
Small, low-traffic
web sites
requiring
database
connectivity.
Cannot handle
heavy traffic from
multiple users.
6
MS SQL SERVER 2005
MS SQL SERVER 2005 – STUDENT EDITION from
MSDNAA
MS SQL SERVER 2008 ** new
MS SQL SERVER 2008 STUDENT EDITION from MSDNAA
installation guide – similar to 2005 edition
All lecture notes are in version 2005
The 2008 interface is similar if not the same.
Section 2
MS SQL Overview
7
MSDN – MS SQL Server 2005 Online Videos
http://msdn2.microsoft.com/en-us/express/aa718391.aspx
•
•
•
•
Learning Resources - Video Series: SQL Server 2005 Express Edition for Beginners
Getting Started with SQL Server Express
This video series is designed specifically for SQL Server beginners—individuals who are interested in learning the basics
of how to create, manage, and connect to SQL Server Express databases. Whether you’re just a beginner or somewhat
familiar with databases, these video lessons will help you get better acquainted with SQL Server 2005 Express.
The series includes almost 9 hours of video-based instruction that walks SQL Server beginners through the steps of
learning about SQL Server databases to actually connecting a SQL Server database to a Web application. Select your
starting point below based on your skill set.
– Introduction
• Learning Video 1: What is a database?
– Designing Tables
• Learning Video 2: Understanding Database Tables and Records
• Learning Video 3: More about Column Data Types and Other Properties
• Learning Video 4: Designing Relational Database Tables
– Database Functions
• Learning Video 5: Manipulating Database Data
• Learning Video 6: More Structured Query Language
• Learning Video 12: Creating and Using Stored Procedures
• Learning Video 13: Enabling Full-Text Search in your Text Data
– Creating and Using Reports
• Learning Video 10: Getting Started with Reporting Services
• Learning Video 11: Embedding, Packaging and Deploying SQL Server Express Reporting Services
– Database Security
• Learning Video 7: Understanding Security and Network Connectivity
– Database Management
• Learning Video 9: Using SQL Server Management Studio Express
– Publishing to the Web
• Learning Video 8: Connecting your Web Application to SQL Server 2005 Express Edition
Section 2
MS SQL Overview
8
MS SQL Server 2005
Management Studio Express (MSE)
•MSE is the development environments for server based databases. Traditionally installed on
servers only.
•Administrators and Developers access via MS SQL client tools installed on workstation.
•Users access via workstation either by MS SQL client tools or other software packages such as
MS Access, MS VBasic, Macromedia Dreamweaver, etc
Develop DB via Graphical UI
Develop DB via Scripting UI
Draw ER model in design view
Create tables in design view
Drag and drop relationships links
Automatically creates tables from ER Model
Easy to navigate existing DBs
Write SQL code to reflect ER model
SQL code held in a Script File
Script Files of SQL code in notepad or word
Use SQL code to create tables & relationships
More powerful, less intuitive
Section 2
MS SQL Overview
9
Management Studio Graphical User Interface
Click Databases
Note additional server option
Section 2
MS SQL Overview
10
Note SUMMARY tag.
Available from VIEW menu.
Expand databases by clicking +
Section 2
MS SQL Overview
11
Management Studio Graphical User Interface (GUI)
- develop and draw ER model to implement database
Library ERD
Section 2
MS SQL Overview
• Use the GUI to develop
your ER model.
• Add, Delete and Modify
Tables, Fields and
Relationships (links).
• SQL Script Code
automatically generated.
• Also develop Views,
Queries Reports etc
12
•
•
Management Studio Scripting User Interface SUI
- develop and write SQL Code to implement database
The most popular, and now standard, language for manipulating tables in a relational
database is SQL.
SQL, often known as a query language, is a combined DDL, DML and DCL used with
relational databases.
• Data Definition Language (DDL)
– is used to specify the data in a database.
– The DDL statements define database objects, eg databases, tables, views,
indexes, users, constraints, user-defined data types: CREATE, DROP, ALTER
• Data Manipulation Language (DML)
– is used to access the data in a database.
– The DML statements manipulate data: SELECT, INSERT, DELETE, UPDATE
• Data Control Language (DCL)
– is used to control access to the data in a database.
– The DCL statements control access to data: GRANT, DENY, REVOKE
Section 2
MS SQL Overview
13
SQL Query Code Example
USE Restaurants
GO
USE MASTER
GO
-- If the database already exists, drop it
IF EXISTS(SELECT * FROM
sysdatabases WHERE
name='Restaurants')
DROP DATABASE Restaurants
GO
-- Create the Restaurants database
CREATE DATABASE Restaurants
GO
Section 2
-- Create the Widgets table in Restaurants
CREATE TABLE RestaurantTable
(
RestaurantId INT NOT NULL
PRIMARY KEY IDENTITY(1,1),
RestaurantName VARCHAR(50) NOT
NULL,
Rating SMALLINT DEFAULT 3,
AvgMealPrice MONEY NOT NULL,
ReservationReqd BIT NOT NULL
DEFAULT 0
)
GO
MS SQL Overview
14
SQL Server Object Names
• Standard Identifiers
–
–
–
–
–
–
–
Can contain from one to 128 characters, including letters, symbols (_ @ or #) and numbers.
No embedded spaces are allowed.
The first character must be alphabetic.
A name beginning with @ denotes a local variable or parameter.
A name beginning with # denotes a temporary table or procedure.
A name beginning with ## denotes a global temporary object.
NB: Names for temporary objects shouldn’t exceed 116 characters including # or ## as SQL
Server gives them an internal numeric suffix.
• Delimited Identifiers
– Do not comply with the rules for standard identifiers and must, therefore, always be
delimited.
– You can use delimited identifiers when:
– Names contain embedded spaces.
– Reserved words are used for object names or portions of object names.
– You must enclose delimited identifiers in square brackets or quotation marks when you use
them in Transact-SQL statements, eg:
– SELECT * FROM [Blanks In Table Name]
– SELECT * FROM “Blanks In Table Name”
– NB:You can always use bracketed delimiters but can only use quotation marks if the SET
QUOTED_IDENTIFIER option is on.
Section 2
MS SQL Overview
15
Additional SQL Resources on the SQL Website.
MS SQL Server 2005
Section 2
home
1.1 sql2005.intro
home
1.2 express version installation guide
home
1.3 student version installation guide
home
1.4 MSDN - MS SQL Server 2005 Video Resources
UoT/HM
2. Management Studio Guilde
UoT/HM
3. Create a Database via ERD (student)
UoT/HM
4. Create a Database via Tables (unispares)
UoT/HM
5. Create a Database via SQL Script Code (student1)
UoT/HM
6. SQL Query Introduction (customer)
home
7. MS Access <-> MS SQL Server (library)
home
8. MS Access <-> MS SQL DDL & DML (library)
UoT/HM
9. MS SQL - Detach and Attach databases
MS SQL Overview
16
FURTHER READING
• Review the attached set of SQL notes over the next four weeks
to reinforce your SQL skills.
– Data Models are converted to schemas which are readable by the database
management system.
– Notation standardised through SQL and XML
– Schemas describe data.
– Described as tables (relations) for relational databases.
– Definition of Columns of tables based on domains (sets of valid values).
– Metadata describes data. Schemas form part of the metadata for a system.
Key Relational and SQL
Concepts (part 1 of 3)
SQL_Data_Definition
SQL Sub Queries
Section 2
Key Relational and SQL
Concepts (part 2 of 3)
Domains
Metadata
SQL Groups
MS SQL Overview
Key Relational and SQL
Concepts (part 3 of 3)
XML
SQL Data Definition Views
17
End of Lecture
Section 2
MS SQL Overview
18
Download