Download Database Concepts - Syracuse University

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Extensible Storage Engine wikipedia , lookup

DBase wikipedia , lookup

Tandem Computers wikipedia , lookup

Team Foundation Server wikipedia , lookup

Database wikipedia , lookup

Oracle Database wikipedia , lookup

Ingres (database) wikipedia , lookup

Microsoft Access wikipedia , lookup

Relational algebra wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Btrieve wikipedia , lookup

Clusterpoint wikipedia , lookup

Null (SQL) wikipedia , lookup

Database model wikipedia , lookup

Relational model wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

SQL wikipedia , lookup

PL/SQL wikipedia , lookup

Transcript
STRUCTURED QUERY
LANGUAGE
SQL
Fact of the Week:
According to the 2010 outlook from the
BLS 286,600 new Computer, Network, and
Database administrator jobs will be added
in the next decade.
Learning Objectives




Describe and use basic SQL commands
Explain how and why SQL is used, and why its
important
Compare and contrast DML and DDL
Use SQL commands to create metadata structures
and perform CRUD operations.
Brief History of SQL






1970– E. Codd develops relational database
concept
1974-1979–System R with Sequel (later SQL)
created at IBM Research Lab
1979–Oracle markets first relational DB with
SQL
1986–ANSI SQL standard released
1989, 1992, 1999, 2003, 2007–Major ANSI
standard updates
Current–SQL is supported by most major
database vendors at 1999, 2003 and 2007
http://www.jcc.com/sql.htm
The purpose of the SQL standard
Syntax and
Semantics
Allow for
Growth /
Enhancement
Levels:
Minimal (L1)
Complete
(L2)
SQL
Intrinsic
Data
Structures
Portability
Benefits of the SQL standard






Reduced training costs
Productivity
Application portability
Application longevity
Reduced dependence on a single vendor
Cross-system communication
Yes. The standard helps, but each of these benefits
is not as realized as other standards, such as HTML
The SQL Environment
Server
Instance
Catalog (db)
Schema
Catalog (db)
Schema
Objects
Instance
In this class we use:
•SQL Server ist-s-students,1533
•With the default instance
•Each student has their own catalog (db)
•Default schema (dbo)
SQL Server 2005: ist-s-students

Other Information:
SQL Dialect: T-SQL / Transact-SQL
 Case Sensitive Collation?: Yes
 System tables used to represent meta data.
 Client / Server over TCP/IP Connect to database using:
 host/IP, port number, logon, password
 Client software used to manage data/meta data on server
 Everything can be expressed in SQL!


Naming Rules for Objects in SQL Server:
Up to 128 characters long
 Must begin with a letter
 Can contain digits, letters, _, .
 Spaces can be used but should be avoided.

My Naming Conventions
What
Mike’s Convention
Rationale for use
All object names
Use all lower case letters.
Disambiguation: eg. Employee
vs. employee for example
All object names
Use underscore in place of
SPACE
Avoid the need to place brackets
around identifiers.
employee_phone_number vs.
[employee phone number]
Tables
Pluralize
Should be employees table,
since it contains more than one
employee 
Tables
Qualify with logical schema
Disambiguation of objects
within the same database: eg.
fudgemart_employees vs.
fudgeflix_employees
Column names
Quality with table name
Helps define scope of object.
Eg. employee_zipcode .vs
vendor_zipcode
Constraints
pk= primary key
fk=foreign key
u=unique
ck=check
i=index
Disambiguation of constraints,
for example:
ck_vendor_zipcode .vs.
fk_vendor_zipcode
SQL: Language Breakdown
Domain
SQL Commands
Objects
Metadata
(DDL)
CREATE
ALTER
DROP
Tables, functions,
views, procedures, etc
DATA
(DML)
C - INSERT
R - SELECT
U - UPDATE
D - DELETE
Tables (as a target)
Security
(DCL)
GRANT
REVOKE
Tables, functions,
views, procedures, etc.
Transactions
(DTL)
BEGIN TRANS
COMMIT
ROLLBACK
Controls DML
statements
A Guide to Syntax Diagrams
KEYWORD
SQL keywords are in upper case. They
must be entered exactly as shown.
variable This represents a user-defined value.
...n
This implies the aforementioned pattern
repeats indefinitely.
|
The “OR” Operator, meaning select only
one item from those in the OR list.
{ }
The contents in curly braces are required.
[ ]
The contents of the braces are optional.
Example: Syntax Diagrams
THE [adjective[, …n]]
{CAT|DOG|HORSE} verb [adverb].

Examples (syntactically correct???):
 The
old dog ate.
 The fat cat walked slowly.
 The sick, brown, ugly horse died.
 The dog slept lazily.
STRUCTURED QUERY
LANGUAGE
On to the Demos…
SQL Basics