Top Banner
HSCI 709 SQL Data Definition Language
26

HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

Dec 31, 2015

Download

Documents

Alaina Dixon
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

HSCI 709

SQL Data Definition Language

Page 2: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

SQL Standard• SQL-92 was developed by the INCITS Technical Committee H2 on

Databases. • SQL-92 was designed to be a standard for relational database

management systems (RDBMSs)• Next Version: SQL3

– Will enhance SQL into a computationally complete language for the definition and management of persistent, complex objects.

• generalization and specialization hierarchies• multiple inheritance• user defined data types• triggers and assertions• support for knowledge based systems• recursive query expressions• and additional data administration tools• abstract data types (ADTs)• object identifiers• Methods• Inheritance, Polymorphism, Encapsulation, and all of the other facilities

normally associated with object data management

Page 3: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

SQL Programmer

• You have been doing it and you did not know it.

Page 4: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

SQL Programmer

• You have been doing it and you did not know it.

Page 5: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

SQL Components

SQL

DCL DDL DML

DBA Activities

Create UsersDelete UsersGrant privilegesImplement AccessSecurity

RDBMS Structure

Create/Delete DBs

Create/Delete TablesAlter Tables

Data I/O

Create Record

Read Record

Update Record

Delete Record

Page 6: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

"Create Table" Syntax

CREATE TABLE <myTable>

(<Field1> <DataType>, <Field2> <DataType>,…);

Page 7: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

"Create Table" Syntax

CREATE TABLE <myTable>

(<Field1> <DataType>, <Field2> <DataType>,…);

CREATE TABLE PAT

(PAT_ID INT, PAT_FM TEXT(20),PAT_LNM TEXT(35));

Page 8: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

Create Table in MS Access(1)

Page 9: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

Create Table in MS Access(2)

Page 10: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

Create Table in MS Access(3)

TABLE NAME FIELD NAME DATA TYPE

Page 11: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

"Alter Table" Statement

• This statement can be used to:– Add new columns– Delete defined columns– Make a column the primary key– Change column data types– Change table names*– Make a column a foreign key– Add constraints to a column, e.g., indexing

* NOT SUPPORTED IN MS ACCESS

Page 12: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

Adding a New Column

ALTER TABLE <myTable ADD COLUMN <NewField> <DataType>;

Page 13: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

Adding a New Column

ALTER TABLE PAT ADD COLUMN PAT_DESCR MEMO;

ALTER TABLE <myTable> ADD COLUMN <NewField> <DataType>;

Page 14: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

MS Access Effects

Page 15: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

Deleting a Column

ALTER TABLE <myTable> DROP COLUMN <Field>;

Page 16: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

Deleting a Column

ALTER TABLE <myTable> DROP COLUMN <Field>;

ALTER TABLE PAT DROP COLUMN PAT_DESCR;

Page 17: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

MS Access Effects

Page 18: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

Creating a PK

ALTER TABLE <myTable> ADD PRIMARY KEY(<Field>);

Page 19: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

Creating a PK

ALTER TABLE PAT ADD PRIMARY KEY(PAT_ID);

ALTER TABLE <myTable> ADD PRIMARY KEY(<Field>);

Page 20: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

MS Access Effects

Page 21: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

Changing Data Types

ALTER TABLE <myTable> ALTER COLUMN <field> <newDataType>;

Page 22: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

Changing Data Types

ALTER TABLE <myTable> ALTER COLUMN <field> <newDataType>;

ALTER TABLE PAT ALTER COLUMN PAT_LNM TEXT(55);

Page 23: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

Foreign KeysPAT

PAT_ID INT

PAT_FNM TEXT(20)PAT_LNM TEXT(35)

CLNCIAN

CLNCIAN_ID INT

CLNCIAN_NM TEXT(250)PAT_ID

Page 24: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

Foreign Keys

CREATE TABLE CLNCIAN (CLNCIAN_ID INTEGER PRIMARY KEY, CLNCIAN_NM TEXT (55), PAT_ID INT, CONSTRAINT FKPatId FOREIGN KEY (PAT_ID) REFERENCES PAT);

PAT

PAT_ID INT

PAT_FNM TEXT(20)PAT_LNM TEXT(35)

CLNCIAN

CLNCIAN_ID INT

CLNCIAN_NM TEXT(250)PAT_ID

Page 25: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

MS Access

Page 26: HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.

Take Home Lesson

SQL commands can do what Graphical User Interface does in

Access