Lecture 06 - Creating Tables Using SQL
Lecture 06 - Creating Tables Using SQL
Advanced Databases
Lecture 4
Creating Relations using SQL
Systems Development Database
Life Cycle Development Process
Project Identification Enterprise modeling
and Selection
Project Initiation
and Planning Conceptual data modeling
Analysis
3
SQL Environment
Catalog
A set of schemas that constitute the description of a
database
Schema
The structure that contains descriptions of objects
created by a user (base tables, views, constraints)
Data Definition Language (DDL)
Commands that define a database, including creating,
altering, and dropping tables and establishing
constraints
Data Manipulation Language (DML)
Commands that maintain and query a database
Data Control Language (DCL)
Commands that control a database, including
administering privileges and committing data 4
SQL Data types
(from Oracle 9i)
String types
CHAR(n) – fixed-length character data, n characters long
Maximum length = 2000 bytes
VARCHAR2(n) – variable length character data, maximum
4000 bytes
LONG – variable-length character data, up to 4GB. Maximum
1 per table
Numeric types
NUMBER(p,q) – general purpose numeric data type
INTEGER(p) – signed integer, p digits wide
FLOAT(p) – floating point in scientific notation with p binary
digits precision
Date/time type
DATE – fixed-length date/time in dd-mm-yy form
5
6
SQL Database Definition
Data Definition Language (DDL)
Major CREATE statements:
CREATE SCHEMA – defines a portion of the
database owned by a particular user
CREATE TABLE – defines a table and its columns
CREATE VIEW – defines a logical table from one
or more views
Other CREATE statements: CHARACTER SET,
COLLATION, TRANSLATION, ASSERTION,
DOMAIN
7
The following slides create tables for
this enterprise data model
8
Relational Data Model
9
Identifying foreign keys and establishing relationships
Primary key of
parent table
Foreign key of
dependent table
10
Non-nullable specifications
Primary key
11
Controlling the values in attributes
Domain constraint
PRIMARY KEY (PRODUCT_ID));
12