Chapter 3:SQL Data Definition Basic Query Structure Set Operations Aggregate Functions Null Values Nested Subqueries Complex Queries Views Modification of the Database Joined Relations** Database System Concepts,5th Edition,Oct 5,2006 3.2 @Silberschatz,Korth and Sudarshan
Database System Concepts, 5 3.2 ©Silberschatz, Korth and Sudarshan th Edition, Oct 5, 2006 Chapter 3: SQL Data Definition Basic Query Structure Set Operations Aggregate Functions Null Values Nested Subqueries Complex Queries Views Modification of the Database Joined Relations**
History IBM Sequel language developed as part of System R project at the IBM San Jose Research Laboratory Renamed Structured Query Language(SQL) ANSI and ISO standard SQL: SQL-86 SQL-89 SQL-92 SQL:1999(language name became Y2K compliant!) SQL:2003 Commercial systems offer most,if not all,SQL-92 features,plus varying feature sets from later standards and special proprietary features. Not all examples here may work on your particular system. Database System Concepts,5th Edition,Oct 5,2006 3.3 Silberschatz,Korth and Sudarshan
Database System Concepts, 5 3.3 ©Silberschatz, Korth and Sudarshan th Edition, Oct 5, 2006 History IBM Sequel language developed as part of System R project at the IBM San Jose Research Laboratory Renamed Structured Query Language (SQL) ANSI and ISO standard SQL: SQL-86 SQL-89 SQL-92 SQL:1999 (language name became Y2K compliant!) SQL:2003 Commercial systems offer most, if not all, SQL-92 features, plus varying feature sets from later standards and special proprietary features. Not all examples here may work on your particular system
Data Definition Language Allows the specification of not only a set of relations but also information about each relation,including: The schema for each relation. The domain of values associated with each attribute. Integrity constraints The set of indices to be maintained for each relations. Security and authorization information for each relation. The physical storage structure of each relation on disk. Database System Concepts,5th Edition,Oct 5,2006 3.4 Silberschatz,Korth and Sudarshan
Database System Concepts, 5 3.4 ©Silberschatz, Korth and Sudarshan th Edition, Oct 5, 2006 Data Definition Language The schema for each relation. The domain of values associated with each attribute. Integrity constraints The set of indices to be maintained for each relations. Security and authorization information for each relation. The physical storage structure of each relation on disk. Allows the specification of not only a set of relations but also information about each relation, including:
Domain Types in SQL char(n).Fixed length character string,with user-specified length n. varchar(n).Variable length character strings,with user-specified maximum length n. int.Integer(a finite subset of the integers that is machine-dependent). smallint.Small integer(a machine-dependent subset of the integer domain type). numeric(p,d).Fixed point number,with user-specified precision of p digits with n digits to the right of decimal point. real,double precision.Floating point and double-precision floating point numbers,with machine-dependent precision. float(n).Floating point number,with user-specified precision of at least n digits. More are covered in Chapter 4. Database System Concepts,5th Edition,Oct 5,2006 3.5 @Silberschatz,Korth and Sudarshan
Database System Concepts, 5 3.5 ©Silberschatz, Korth and Sudarshan th Edition, Oct 5, 2006 Domain Types in SQL char(n). Fixed length character string, with user-specified length n. varchar(n). Variable length character strings, with user-specified maximum length n. int. Integer (a finite subset of the integers that is machine-dependent). smallint. Small integer (a machine-dependent subset of the integer domain type). numeric(p,d). Fixed point number, with user-specified precision of p digits, with n digits to the right of decimal point. real, double precision. Floating point and double-precision floating point numbers, with machine-dependent precision. float(n). Floating point number, with user-specified precision of at least n digits. More are covered in Chapter 4
Create Table Construct An SQL relation is defined using the create table command: create table r(A1 D1,A2 D2,...,An Dn (integrity-constraint ) (integrity-constraintk)) r is the name of the relation each A,is an attribute name in the schema of relation r D,is the data type of values in the domain of attribute A, Example: create table branch (branch name char(15)not null, branch_city char(30), assets integer) Database System Concepts,5th Edition,Oct 5,2006 3.6 @Silberschatz,Korth and Sudarshan
Database System Concepts, 5 3.6 ©Silberschatz, Korth and Sudarshan th Edition, Oct 5, 2006 Create Table Construct An SQL relation is defined using the create table command: create table r (A1 D1 , A2 D2 , ..., An Dn , (integrity-constraint1 ), ..., (integrity-constraintk )) r is the name of the relation each Ai is an attribute name in the schema of relation r Di is the data type of values in the domain of attribute Ai Example: create table branch (branch_name char(15) not null, branch_city char(30), assets integer)