Understanding the Role & History of SQL in Database Management, Study Guides, Projects, Research of Introduction to Database Management Systems

An overview of sql (structured query language), its history, roles, and basic concepts. Sql is a declarative language used for managing and manipulating data in relational databases. Sql's roles as a data definition language (ddl), data control language (dcl), and data manipulation language (dml). It also discusses sql statements, data types, and basic queries.

Typology: Study Guides, Projects, Research

2011/2012

Uploaded on 02/15/2012

arien
arien šŸ‡ŗšŸ‡ø

4.8

(24)

309 documents

1 / 43

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Announcements
• Written Homework 1 due Nov 2
– See course web page
– Exercises 5.12, 5.15, 6.17, 6.20, 6.22 (a,c,f only).
• Today
– SQL (chapter 8)
– Instructional environment overview
• Where we are heading
– SQL programming (chapter 9)
– Database design (ch 10), practical design (ch 12),
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b

Partial preview of the text

Download Understanding the Role & History of SQL in Database Management and more Study Guides, Projects, Research Introduction to Database Management Systems in PDF only on Docsity!

Announcements

•^ Written Homework 1 due Nov 2– See course web page– Exercises 5.12, 5.15, 6.17, 6.20, 6.22 (a,c,f only).•^ Today– SQL (chapter 8)– Instructional environment overview•^ Where we are heading– SQL programming (chapter 9)– Database design (ch 10), practical design (ch 12),

A brief history of SQL

•^ In 1970s, team at IBM implemented System Rbased on the relational model•^ SEQUEL (Structured English Query Language)was created to manipulate system R data•^ In late 1970s Oracle V2 was first to market•^ IBMs system 38 followed•^ Adopted as ANSI standard in ā€˜86 and ISO in ’87– ā€œOfficialā€ pronunciation is ā€œes-queue-elā€ā€“ SQL3 (1999) last major update to standard•^ Currently vendors ā€œself certifyā€ compliance ;-)

SQL, the reality

•^ every vendor supports slightly different versionof SQL•^ Thus, oracle SQL for example, will not bedirectly portable to say Microsoft SQL

SQL has multiple roles

•^ Data definition language (DDN)– Eg, define relation schemas•^ Data control language (DCL)– Eg, security and authorization controls•^ Data manipulation language (DML)– Query for tuples– Insert, delete and modify tuples•^ SQL supports constraints, transactions & views•^ SQL standard does not support indexes

SQL DDL statements

•^ SQL has two key DDL commands^ –^ CREATE SCHEMA

• Creates a database schema – CREATE TABLE • Define a relation created in the context of somedatabase created with CREATE SCHEMA

•^ Other DDL commands^ –^ CREATE VIEW^ –^ CREATE DOMAIN

• Not in mySQL.

CREATE

TABLE

CREATE

TABLE

<schema_name>.<table_name>( col1_name

col1_type, col2_name

col2_type, ...colM_name

colM_type, constraint1,...,constraintN

example with no constraints: CREATE

TABLE

dept_locations

dnumber

integer(4), dlocation

varchar(15)

if schema name isomitted, table createdin the default DBstatement ends withsemi-colon

Adding Constraints in

CREATE

TABLE

CREATE

TABLE

DEPT

DNAME

VARCHAR(10)

NOT^

NULL,

DNUMBER

INTEGER

NOT^ NULL,

MGRSSN

CHAR(9),

MGRSTARTDATE

CHAR(9),

PRIMARY

KEY^

(DNUMBER),

UNIQUE

(DNAME),

FOREIGN

KEY^

(MGRSSN)

REFERENCES

EMP^

other options:

DEFAULT,

CHECK,

UNIQUE

Dnumber

INT^

CHECK(Dnumber

>^0

AND^ Dnumber

<^ 21)

CREATE^

TABLE^ product

(category

INT^ NOT

NULL,^

id^ INT^

NOT^ NULL,

price^ DECIMAL,PRIMARY

KEY(category,

id))^ ENGINE=INNODB;

CREATE^

TABLE^ customer

(id^ INT

NOT^ NULL,PRIMARY^ KEY^ (id))

ENGINE=INNODB;

CREATE^

TABLE^ product_order

(no INT

NOT^ NULL

AUTO_INCREMENT, product_category

INT^ NOT

NULL,

product_id

INT^ NOT

NULL, customer_id

INT^ NOT

NULL,

PRIMARY

KEY(no), INDEX^ (product_category,

product_id),

FOREIGN

KEY^ (product_category,

product_id)

REFERENCES

product(category,

id)

ON^ UPDATE

CASCADE

ON^ DELETE

RESTRICT,

INDEX^ (customer_id),FOREIGN

KEY^ (customer_id)REFERENCES^ customer(id))

ENGINE=INNODB;

Referential Triggered Action(from mySQL ā€œhelp constraintā€)

defines ā€œstorage engineā€

Basic Data Types and Domains

•^ Numeric– INT, FLOAT, DECIMAL(precision,scale)•^ String– char(n), varchar(n)•^ Boolean•^ Date•^ Timestamp•^ BLOB (binary large object)– tinyblob, mediumblob, largeblob•^ Enum– enum(ā€˜red’,’blue’,’green’);•^ set– set( ā€˜red’, ā€˜blue’, ā€˜green’);

Retrieval Queries in SQL

•^ SQL has one basic statement for retrieving informationfrom a database; the

SELECT

statement

  • This is

not the same as

the SELECT operation of the relational

algebra• Important distinction between SQL and the formalrelational model:– SQL allows a table (relation) to have two or more tuples that areidentical in all their attribute values– Hence, an SQL relation (table) is a

multi-set

(sometimes called

a^ bag ) of tuples; it is

not^ a set of tuples

•^ SQL relations can be constrained to be sets byspecifying PRIMARY KEY or UNIQUE attributes, or byusing the DISTINCT option in a query

Retrieval Queries in SQL (contd.)

•^ A^ bag

or^ multi-set

is like a set, but an element

may appear more than once.– Example: {A, B, C, A} is a bag. {A, B, C} is also a bagthat also is a set.– Bags also resemble lists, but the order is irrelevant ina bag.• Example:– {A, B, A} = {B, A, A} as bags– However, [A, B, A] is not equal to [B, A, A] as lists

  • Relational Database Schema--Figure 5.