Lecture Fundamentals of Database Systems - Chapter 8: SQL-99 - Schema Definition, Basic Constraints, and Queries
Thông tin tài liệu:
Nội dung trích xuất từ tài liệu:
Lecture Fundamentals of Database Systems - Chapter 8: SQL-99 - Schema Definition, Basic Constraints, and QueriesCopyright © 2004 Pearson Education, Inc. Chapter 8 SQL-99: Schema Definition, BasicConstraints, and Queries Copyright © 2004 Pearson Education, Inc. Data Definition, Constraints, and Schema Changes Used to CREATE, DROP, and ALTER the descriptions of the tables (relations) of a database Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Ramez Elmasri and Shamkant Navathe Slide 8-3 CREATE TABLE Specifies a new base relation by giving it a name, and specifying each of its attributes and their data types (INTEGER, FLOAT, DECIMAL(i,j), CHAR(n), VARCHAR(n)) A constraint NOT NULL may be specified on an attribute CREATE TABLE DEPARTMENT ( DNAME VARCHAR(10) NOT NULL, DNUMBER INTEGER NOT NULL, MGRSSN CHAR(9), MGRSTARTDATE CHAR(9) ); Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Ramez Elmasri and Shamkant Navathe Slide 8-4 CREATE TABLE In SQL2, can use the CREATE TABLE command for specifying the primary key attributes, secondary keys, and referential integrity constraints (foreign keys). Key attributes can be specified via the PRIMARY KEY and UNIQUE phrases 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 ); Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Ramez Elmasri and Shamkant Navathe Slide 8-5 DROP TABLE Used to remove a relation (base table) and its definition The relation can no longer be used in queries, updates, or any other commands since its description no longer exists Example: DROP TABLE DEPENDENT; Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Ramez Elmasri and Shamkant Navathe Slide 8-6 ALTER TABLE Used to add an attribute to one of the base relations The new attribute will have NULLs in all the tuples of the relation right after the command is executed; hence, the NOT NULL constraint is not allowed for such an attribute Example: ALTER TABLE EMPLOYEE ADD JOB VARCHAR(12); The database users must still enter a value for the new attribute JOB for each EMPLOYEE tuple. This can be done using the UPDATE command. Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Ramez Elmasri and Shamkant Navathe Slide 8-7Features Added in SQL2 and SQL-99 CREATE SCHEMA REFERENTIAL INTEGRITY OPTIONS Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Ramez Elmasri and Shamkant Navathe Slide 8-8 CREATE SCHEMA Specifies a new database schema by giving it a name Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Ramez Elmasri and Shamkant Navathe Slide 8-9 REFERENTIAL INTEGRITY OPTIONS We can specify RESTRICT, CASCADE, SET NULL or SET DEFAULT on referential integrity constraints (foreign keys) 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 ON DELETE SET DEFAULT ON UPDATE CASCADE ); Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Ramez Elmasri and Shamkant Navathe Slide 8-10REFERENTIAL INTEGRITY OPTIONS (continued)CREATE TABLE EMP ( ENAME VARCHAR(30) NOT NULL, ESSN CHAR(9), BDATE DATE, DNO INTEGER DEFAULT 1, SUPERSSN CHAR(9), PRIMARY KEY (ESSN), FOREIGN KEY (DNO) REFEREN ...
Tìm kiếm theo từ khóa liên quan:
Fundamentals of Database Systems Database Systems Basic constraints Schema definition Create schema SQL-99Tài liệu liên quan:
-
Ebook Spatial database systems: Design, implementation and project management – Part 2
332 trang 228 0 0 -
Ebook Database systems: Design, implementation, and management (12th)
818 trang 86 0 0 -
Lecture Principles of distributed database systems - Chapter 8: Distributed query optimization
53 trang 27 0 0 -
Ebook Fundamentals of database systems (Seventh edition): Part 2
786 trang 27 0 0 -
Lecture Database Systems - Lecture 11
46 trang 25 0 0 -
Lecture Database Systems - Chapter 5: Relational algebra (Trương Quỳnh Chi)
65 trang 25 0 0 -
Ebook Database management systems (2nd edition): Part 1
438 trang 25 0 0 -
Lecture Principles of distributed database systems - Chapter 6: Distributed query processing
15 trang 24 0 0 -
Lecture Database Systems - Chapter 8: Data storage, Indexing structures for files (Trương Quỳnh Chi)
57 trang 24 0 0 -
Lecture Principles of distributed database systems - Chapter 3: Distributed database design
65 trang 23 0 0