Docsity

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

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.