Docsity

SQL Data Types, Data Definition Language (DDL) Commands and Integrity Constraints - Prof. , Study notes of Computer Science

Partial preview of the text

Download SQL Data Types, Data Definition Language (DDL) Commands and Integrity Constraints - Prof. and more Study notes Computer Science in PDF only on Docsity!

What you should have learned after this lecture ... ย‰ what the main^ data types

of SQL are ย‰^ what the main

data definition language

( DDL ) commands of SQL are

โˆ’^ double precision

double-precision

floating-point

number^ with

computer-

dependent precision โˆ’^ float ( n )^

floating-point number with user specified precision of atleast^ n^ digits โˆ’^ bit ( n )^

bit string of fixed length

n

โˆ’^ bit varying

( n )^ bit string of variable length with user specified maximumlength

n โˆ’^ blob^

binary large object

, byte sequence of variable length up to 4 GB, for the representation of extremely large objects(e.g. multimedia objects, video sequences, geo-objects) โˆ’^ date^

calendar date with year (4 digits), month (2 digits), day (2digits), format: YYYY-MM-DD โˆ’^ time^

time^ of^ day,^

in^ hours,^ minutes,

and^ seconds,

format:

HH:MM:SS โˆ’^ time with time zone

time difference to GMT (6 digits) โˆ’^ timestamp

value containing date and time of date โˆ’^ interval^

relative value which can increment or decrement an abso-lute value of type

date ,^ time^ or

timestamp , year/month- or day/hour-intervals

ย‰^ unique^ expresses that this attribute is a candidate key. If a candidate key is formedby several attributes

A , ...,^ A , this is specified by the integrity constraint^1 n

unique ( A ,^1

...,^ A ). n Creation of a relation schema ย‰ in SQL no relations but tables (duplicates allowed) ย‰ creation of a schema with the aid of the clause create table^ R

( A D^ ,^ A D^^1^1^2^2

, ...,^ A D , n^ n [< integrity constraint

, ..., < integrity constraint 1

]) k

R^ relation name,

A name of an attribute in the schema of relation i^

R ,^ D domain of i^

Ai

ย‰^ in BNF notation:^ create table

( [, ]*) ::= | ::= [ |

not null^ |^ unique

]

::= [

default^ |

null ] The exact treatment of integrity constraints is discussed later.

ย‰^ integrity constraints^ primary key

( A , ...,^ A ) jj^1 m The attributes^ A , ...,^ A form the primary key of jj^1 m^

R.

ย‰^ example: university schema (with incomplete integrity constraints)^ create table

students(reg-id int not null

name^

varchar (30)^ not null

sem^

int , primary key^

(reg-id)) create table^ professors(pers-id^

int not null , name^

varchar (30)^ not null

room^

int^ unique , rank^

char (2), primary key^

(pers-id))

create table^ is_precondition_of(predecessor

int not null

successor^

int^ not null , primary key^

(predecessor, successor), foreign key^ (predecessor)

references^ lectures(id), foreign key^ (successor)

references^ lectures(id)) create table^ tests(reg-id^

int not null , id^

int not null , pers-id^

int not null , grade^

numeric (2,1), primary key^

(reg-id, id, pers-id), foreign key^ (reg-id)

references^ students(reg-id), foreign key^ (id)

references^ lectures(id), foreign key^ (pers-id)

references^ professors(pers-id))

Change of a relation schema ย‰^ adding a new attribute (a new column) by the clause^ โˆ’^ alter table

add^ โˆ’^ value^ not null

is only allowed if a default value is specified ย‰^ deleting an attribute (a column) from a relation by the clause^ alter table

drop^ Deletion of a relation schema ย‰^ drop table

ย‰^ deletion of schema and relation instanceDeletion of a relation ย‰^ delete from

ย‰^ only the relation instance but not the schema is deleted