DOC PREVIEW
SJSU CMPE 226 - SQL-99

This preview shows page 1-2-3-4-5-33-34-35-36-67-68-69-70-71 out of 71 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

PowerPoint PresentationChapter 8Data Definition, Constraints, and Schema ChangesCREATE TABLESlide 5DROP TABLEALTER TABLEFeatures Added in SQL2 and SQL-99CREATE SCHEMAREFERENTIAL INTEGRITY OPTIONSREFERENTIAL INTEGRITY OPTIONS (continued)Additional Data Types in SQL2 and SQL-99Additional Data Types in SQL2 and SQL-99 (cont.)Retrieval Queries in SQLRetrieval Queries in SQL (cont.)Relational Database Schema--Figure 5.5Populated Database--Fig.5.6Simple SQL QueriesSimple SQL Queries (cont.)Slide 20Aliases, * and DISTINCT, Empty WHERE-clauseALIASESALIASES (cont.)UNSPECIFIED WHERE-clauseUNSPECIFIED WHERE-clause (cont.)USE OF *USE OF DISTINCTSET OPERATIONSSET OPERATIONS (cont.)NESTING OF QUERIESNESTING OF QUERIES (cont.)CORRELATED NESTED QUERIESCORRELATED NESTED QUERIES (cont.)Slide 34Slide 35THE EXISTS FUNCTIONTHE EXISTS FUNCTION (cont.)Slide 38EXPLICIT SETSNULLS IN SQL QUERIESJoined Relations Feature in SQL2Joined Relations Feature in SQL2 (cont.)Slide 43Slide 44AGGREGATE FUNCTIONSAGGREGATE FUNCTIONS (cont.)Slide 47GROUPINGGROUPING (cont.)Slide 50THE HAVING-CLAUSETHE HAVING-CLAUSE (cont.)SUBSTRING COMPARISONSUBSTRING COMPARISON (cont.)Slide 55ARITHMETIC OPERATIONSORDER BYORDER BY (cont.)Summary of SQL QueriesSummary of SQL Queries (cont.)Specifying Updates in SQLINSERTINSERT (cont.)Slide 64Slide 65Slide 66DELETEDELETE (cont.)UPDATEUPDATE (cont.)Slide 71Copyright © 2004 Pearson Education, Inc.Copyright © 2004 Pearson Education, Inc.Chapter 8SQL-99: Schema Definition, Basic Constraints, and QueriesSlide 8-3Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionCopyright © 2004 Ramez Elmasri and Shamkant NavatheData Definition, Constraints, and Schema ChangesUsed to CREATE, DROP, and ALTER the descriptions of the tables (relations) of a databaseSlide 8-4Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionCopyright © 2004 Ramez Elmasri and Shamkant NavatheCREATE 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 attributeCREATE TABLE DEPARTMENT( DNAME VARCHAR(10) NOT NULL,DNUMBER INTEGER NOT NULL,MGRSSN CHAR(9),MGRSTARTDATE CHAR(9) );Slide 8-5Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionCopyright © 2004 Ramez Elmasri and Shamkant NavatheCREATE 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 phrasesCREATE 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 );Slide 8-6Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionCopyright © 2004 Ramez Elmasri and Shamkant NavatheDROP 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;Slide 8-7Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionCopyright © 2004 Ramez Elmasri and Shamkant NavatheALTER 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.Slide 8-8Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionCopyright © 2004 Ramez Elmasri and Shamkant NavatheFeatures Added in SQL2 and SQL-99CREATE SCHEMAREFERENTIAL INTEGRITY OPTIONSSlide 8-9Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionCopyright © 2004 Ramez Elmasri and Shamkant NavatheCREATE SCHEMASpecifies a new database schema by giving it a nameSlide 8-10Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionCopyright © 2004 Ramez Elmasri and Shamkant NavatheREFERENTIAL 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 EMPON DELETE SET DEFAULT ON UPDATE CASCADE );Slide 8-11Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionCopyright © 2004 Ramez Elmasri and Shamkant NavatheREFERENTIAL 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) REFERENCES DEPT ON DELETE SET DEFAULT ON UPDATE CASCADE,FOREIGN KEY (SUPERSSN) REFERENCES EMP ON DELETE SET NULL ON UPDATE CASCADE );Slide 8-12Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionCopyright © 2004 Ramez Elmasri and Shamkant NavatheAdditional Data Types in SQL2 and SQL-99Has DATE, TIME, and TIMESTAMP data typesDATE:–Made up of year-month-day in the format yyyy-mm-ddTIME:–Made up of hour:minute:second in the format hh:mm:ssTIME(i):–Made up of hour:minute:second plus i additional digits specifying fractions of a second–format is hh:mm:ss:ii...iTIMESTAMP:–Has both DATE and TIME componentsSlide 8-13Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionCopyright © 2004 Ramez Elmasri and Shamkant NavatheAdditional Data Types in SQL2 and SQL-99 (cont.)INTERVAL:–Specifies a relative value rather than an absolute value–Can be DAY/TIME intervals or YEAR/MONTH intervals–Can be positive or negative when added to or subtracted from an absolute value, the result is an absolute valueSlide 8-14Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionCopyright © 2004 Ramez Elmasri and Shamkant NavatheRetrieval Queries in SQLSQL has one basic statement for retrieving information from a database; the SELECT statementThis is not the same as the SELECT operation of the relational algebraImportant distinction between SQL and the formal relational model; SQL allows a table (relation) to have two or more tuples that are


View Full Document

SJSU CMPE 226 - SQL-99

Documents in this Course
XML

XML

52 pages

XML

XML

14 pages

Chapter 9

Chapter 9

45 pages

Load more
Download SQL-99
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view SQL-99 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view SQL-99 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?