The Structural Query Language | File Structures and Database Systems | CPSC 332, Study notes of Computer Science

Material Type: Notes; Professor: Wang; Class: File Structures and Database Systems; Subject: Computer Science; University: California State University - Fullerton; Term: Fall 2006;

Typology: Study notes

Pre 2010

Uploaded on 08/16/2009

koofers-user-qji-1
koofers-user-qji-1 ๐Ÿ‡บ๐Ÿ‡ธ

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
8/17/2006 Dr. Wang, Cal State Fullerton 1
SQL-The Structural Query Language
1. CREATE DATABASE
CREATE DATABASE <dbname>;
GRANT ALL ON <dbname>.* TO <user>@localhost
IDENTIFIED BY <password>;
2. CREATE TABLE
CREATE TABLE <tablename>
( <column> <datatype> [<attribute constraint>]
{, <column> <datatype> [<attribute constraint>]}
[ <table constraint> {, <table constraint >}] );
8/17/2006 Dr. Wang, Cal State Fullerton 2
SQL-The Structural Query Language
Datatypes:
CHAR(<size>) (size < 255 bytes)
VARCHAR(<size>) (size < 255 bytes)
BLOB or TEXT (size < 65,535)
MEDIUMBLOB or MEDIUMTEXT (size < 16,777,215)
LONGBLOB or LONGTEXT (size < 4 GigaBytes)
ENUM(<value1>, <value2>,โ€ฆ<valuen>)
TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT are integers of 1, 2, 3,
4, and 8 bytes, respectively.
DECIMAL or NUMERIC(M, D)
FLOAT
DOUBLE PRECISION
DATE (default format YYYY-MM-DD,
e.g. โ€œ1997-10-04โ€)
8/17/2006 Dr. Wang, Cal State Fullerton 3
SQL-The Structural Query Language
Attribute constraints:
NOT NULL
UNIQUE
PRIMARY KEY
๎š„
DEFAULT <value>
Table constraints: [CONSTRAINT <name>]
PRIMARY KEY (<attribute> {, <attribute>})
FOREIGN KEY <attribute> REFERENCES <table>(<attribute>) [ON
DELETE SET NULL | ON DELETE CASCADE]
UNIQUE (<attribute> {, <attribute>})
pf3

Partial preview of the text

Download The Structural Query Language | File Structures and Database Systems | CPSC 332 and more Study notes Computer Science in PDF only on Docsity!

8/17/2006 Dr. Wang, Cal State Fullerton 1

1. CREATE DATABASE

CREATE DATABASE ; GRANT ALL ON .* TO @localhost IDENTIFIED BY ;

  1. CREATE TABLE

CREATE TABLE ( [] {, []} [

{,
}] );

8/17/2006 Dr. Wang, Cal State Fullerton 2

SQL-The Structural Query Language

Datatypes: CHAR() (size < 255 bytes) VARCHAR() (size < 255 bytes) BLOB or TEXT (size < 65,535) MEDIUMBLOB or MEDIUMTEXT (size < 16,777,215) LONGBLOB or LONGTEXT (size < 4 GigaBytes) ENUM(, ,โ€ฆ) TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT are integers of 1, 2, 3, 4, and 8 bytes, respectively. DECIMAL or NUMERIC(M, D) FLOAT DOUBLE PRECISION DATE (default format YYYY-MM-DD, e.g. โ€œ1997-10-04โ€)

SQL-The Structural Query Language

Attribute constraints: NOT NULL UNIQUE PRIMARY KEY ย„ DEFAULT

Table constraints: [CONSTRAINT ] PRIMARY KEY ( {, }) FOREIGN KEY REFERENCES

() [ON DELETE SET NULL | ON DELETE CASCADE] UNIQUE ( {, })

8/17/2006 Dr. Wang, Cal State Fullerton 4

CREATE TABLE STUDENT(SSN numeric(9) primary key, FNAME varchar(20), LNAME varchar(20), SEX enum(โ€˜Mโ€™, โ€˜Fโ€™), DBIRTH date, STADDRESS varchar(20), CITY varchar(20), STATE char(2), ZIPCODE char(5), TELEPHONE numeric(10), MAJOR char(4), CLASS tinyint);

8/17/2006 Dr. Wang, Cal State Fullerton 5

SQL-The Structural Query Language

CREATE TABLE COURSE(CNUM char(7) primary key, CNAME varchar(30), TEXTBOOK varchar(50), UNITS tinyint, DEPARTMENT varchar(30)); CREATE TABLE ENROLL(SNO numeric(9), CNO char(7), GRADE enum(โ€˜Aโ€™, โ€˜Bโ€™, โ€˜Cโ€™, โ€˜Dโ€™, โ€˜Fโ€™, โ€˜Wโ€™), primary key (SNO, CNO), foreign key (SNO) references STUDENT(SSN), foreign key (CNO) references COURSE(CNUM));

SQL-The Structural Query Language

3. DROP

DROP DATABASE ; DROP TABLE ;