3 - Physical Model
3 - Physical Model
Database Design
And
CONSTRAINTS
13.03.2025 Prof. Dr. Nergiz CAGILTAY 1
CREATE TABLE table_name
( { column_name data_type [ DEFAULT
default_expr ]
[ column_constraint [ ... ] ] |
table_constraint
[ CONSTRAINT constraint_name ]
{ NOT NULL | NULL | UNIQUE |
PRIMARY KEY | CHECK (expression)
CONSTRAINT constraint_name ] {
UNIQUE ( column_name [, ... ] )
| PRIMARY KEY ( column_name [,
... ] ) | CHECK ( expression ) |
FOREIGN KEY ( column_name [,
... ] ) REFERENCES reftable [ (
refcolumn [, ... ] ) ]] [ ON DELETE
action ] [ ON UPDATE action ] }
13.03.2025 Prof. Dr. Nergiz CAGILTAY 3
Most Common data types
char(size)
Fixed-length character string. Size is specified
in parenthesis. Max 255 bytes.
varchar(size)
Variable-length character string. Max size is
specified in parenthesis.
number(size)
Number value with a max number of column digits
specified in parenthesis
date Date
valuenumber(size,d)
Number value with a maximum number of digits
of "size" total, with a maximum number of "d"
digits to the right of the decimal.
[CONSTRAINT symbol]
FOREIGN KEY [id]
(index_col_name, ...)
REFERENCES tbl_name
(index_col_name, ...)
[ON DELETE {RESTRICT |
CASCADE | SET NULL |
NO ACTION}]
[ON UPDATE {RESTRICT |
CASCADE | SET NULL |
NO ACTION}]
NO ACTION:
an attempt to delete or update a
primary key value will not be allowed to
proceed if there is a related foreign key
value in the referenced table
13.03.2025 Prof. Dr. Nergiz CAGILTAY 25
Specifying ON DELETE /
ON UPDATE
https://docs.google.com/document/d/1yvVE
mOQhGqiqWLtvN0S40pkKGUhQQK8W/edit