Database Management System LICT 3011 Eyad H. Elshami
Relational DBMS objects RDBMS has many objects: – Table – View – Synonym – Sequence – Index – Procedure/Function
SQL Structured Query Language (SQL) – Data Definition Language (DDL) Create Alter Drop – Data Manipulation Language (DML) insert update Delete – Select
Create Table Create table TABLENAME( Col 1 Name datatypeconstraintdefault, Col 2 Name datatypeconstraintdefault, Col 3 Name datatypeconstraintdefault,. Col x Name datatypeconstraintdefault );
Data types Data TypeUse to store number(n) an integer number within size n digits number(p, s) a real number within size p digits s of them after the floating point. char(n) a fixed length character varchar2(n) a variable length character date date and time raw binary data file with size 2000B Long raw binary file with size 2G BLOB binary file with size 4G
Constraints Not null – Attribute could not be empty Unique – Attribute value could not be duplicated Check – Attribute value must satisfies some condition Primary key – Attribute value satisfies not null, unique, and indexing Foreign key (reference) – Attribute value must be in the reference table
Create table example Create Table College( CID number(2) primary key, Cname varchar2(25) unique not null );
Create table example Create table students( SIDnumber(5) primary key, Sname varchar2(25) not null, Sgender char(1) default ‘m’ check(Sgender in(‘m’,’f’)), Sbdate date, CID number(2) references College(CID), Saveragenumber(5,2) );
Alter Table Alter Table TableName – Add ColumnName datatype default Constraint; – Add Constraint ConstraintName ConstrainType; – Modify ColumnName newdatatype; – Drop column ColumnName; – Drop Constraint ConstraintName;
Alter Examples Alter table students add Sphoto long raw; __________________________________ Alter table students modify sname varchar2(20); _________________________________ Alter table students drop column sphoto;
Alter Examples Alter table students add constraint sname_u unique(sname); __________________________________ Alter table students drop constraint sname_u; _________________________________
Create User, change you password create user UserName identified by Password default tablespace users temporary tablespace temp; alter user UserName identified by Newpassword;
Grant privileges to user Grant srole, unlimited tablespace to USERNAME;
Change you password alter user UserName identified by Newpassword;
Describe a table describe tablename To see the tables name – Select * from tab;