Chapter 6: Basic SQL: Database Systems CS203
Chapter 6: Basic SQL: Database Systems CS203
Chapter 6: Basic SQL: Database Systems CS203
•Terminology:
Table, row, and column used for relational model terms relation,
tuple, and attribute
•CREATE statement
Main SQL command for data definition
•The language has features for : Data definition,
Data Manipulation, Transaction control (Transact-
SQL, Ch. 20), Indexing (Ch.17), Security
specification (Grant and Revoke- see Ch.30),
Active databases (Ch.26), Multi-media (Ch.26),
Distributed databases (Ch.23) etc.
SQL Standards
•SQL has gone through many standards: starting with
SQL-86 or SQL 1.A. SQL-92 is referred to as SQL-2.
•Later standards (from SQL-1999) are divided into
core specification and specialized extensions. The
extensions are implemented for different applications –
such as data mining, data warehousing, multimedia
etc.
•SQL-2006 added XML features (Ch. 13); In 2008 they
added Object-oriented features (Ch. 12).
•SQL-3 is the current standard which started with SQL-
1999. It is not fully implemented in any RDBMS.
Schema and Catalog Concepts in SQL
Numeric
Data Type
Floating Formatted
Integer
Point Numbers
DOUBLE
INTEGER INT SMALLINT FLOAT REAL Decimal(i,j) Numeric(i,j)
PRECISION
Attribute Data Types and Domains in
SQL
Character
String
Large Text
Varying
Fixed Length Values
length
(KB,MB,GB)
Attribute Data Types and Domains in
SQL
Bit String
Large Binary
Fixed Length Varying length
Values(Kb,Mb,Gb)
Attribute Data Types and Domains in
SQL
•Boolean Data Type
•True
•False
•NULL
•Time
•HH:MM:SS
•Date
•YYYY-MM-DD
•Multiple mapping functions available in RDBMSs to change date formats
•Timestamp
•TIMESTAMP ‘2014-09-27 09:12:47.648302’
•Interval
•Specifies a relative value that can be used to increment or decrement an
absolute value of a date, time, or timestamp
•DATE, TIME, Timestamp, INTERVAL data types can be cast or converted to
string formats for comparison
Attribute Data Types and Domains in
SQL
•Domain
Name used with the attribute specification
Makes it easier to change the data type for a domain
that is used by numerous attributes
Improves schema readability
Example:
CREATE DOMAIN SSN_TYPE AS CHAR(9);
•TYPE
User Defined Types (UDTs) are supported for object-
oriented applications. (See Ch.12) Uses the command:
CREATE TYPE