Languages of DBMS
Data Definition, Relational Data Definition Language DDL
Manipulation and Data Control define the logical schema (relations, views etc) Using SQL and storage schema stored in a Data Dictionary Data Manipulation Language DML
Manipulative populate schema, update database
Retrieval querying content of a database Data Control Language DCL
permissions, access control etc...
Defining a Relation Data Definition:Creating tables create table student create table accountants (studentno number(8) primary key, as(select studno, name, tutor, year givenname char(20), from student where hons = ‘ca’); surname char(20), hons char(3) check (hons in ('cis','cs','ca','pc','cm','mcs')), Can specify column names, default values tutorid number(4), and integrity constraints (except referential) yearno number(1) not null, Datatypes and lengths derived from query constraint year_fk Not null constraints passed on from query foreign key (yearno) references year(yearno), tables constraint super_fk foreign key (tutorid) references staff(staffid));
Data Definition: Altering Data Definition: Create Table Relations create table enrol (studno number(8),courseno char(5), alter table student primary key (studno, courseno), add (address char(20), cluster (studno), default null); labmark number(3) check (labmark between 0 and 100), exammark number(3) alter table student check (exammark between 0 and 100), modify ( not null); constraint stud_fk name foreign key (studno) references student, this won’t work if there are any nulls in constraint course_fk foreign key (courseno) references course); the name column
1 Data Manipulation: Insert Operator Inserting Tuples into a Relation Course courseno subject equip cs250 prog sun cs150 prog sun insert into table cs260 graphics sun insert into weak_students cs270 elec pc where search-condition cs280 design sun (studno,name,courseno,exammark) cs290 specs paper where (select s.studno,name,courseno,exammark cs390 specs sun from enrol, student s insert (cs310, elec, sun) into course; where exammark <= 40 and enrol.studno = s.studno ); insert into course (courseno,subject,equip) values (‘cs310’, ‘elec’, ‘sun’); insert into course values (‘cs310’, ‘elec’, NULL);
Data Manipulation: Update Insertion Anomalies Operator An insert operation might voliate the uniqueness update update enrol and minimality properties of the primary key of table set column = expression set labmark = labmark * 1.1 the referential integrity constraint [where search-condition] where courseno = ‘cs250’; insert (cs250,databases,sun) into course
COURSE Modifies a tuple or tuples of a relation courseno subject equip cs250 prog sun Don’t violate constraints as long as the modified cs150 prog sun cs280 design sun attributes are not primary keys or foreign keys cs290 specs paper Update of a primary key corresponds to a deletion cs390 specs sun followed by an insertion Insertion anomalies can be corrected by Update of a foreign key attribute is legal only if the rejecting the insertion new value corresponds to an existing tuple in the correcting the reason for rejecting the update referenced relation or is null
Data Manipulation: Delete
Operator delete from course Delete Operator delete where equip = ‘pc’; from table delete from student [where search-condition] delete from student where studno in where year = ‘3’ and(hons (select != ‘mi’ or hons <> ‘si’); student.studno from enrol e, teach t, student s Deletes a tuple or a set of tuples from a relation where t.lecturer = ‘woods’ Might violate the referential integrity constraint and t.courseno = e.courseno Anomalies can be overcome by and e.studno = s.studno); rejecting the deletion cascading the deletion (delete tuples that reference deleted tuple) modifying the referencing attribute values
2 Data Control: Data Sharing Data Control: Data Sharing and Security and Security grant all Permissions, access control etc... privilege, privilege2… | on table | view to userID | roleID create view myyear as select * from student grant select on student to bloggsf; where year in (select year from student Grant can be attached to any combination of select, insert, update, delete, alter where name = user) with check option Restricting access to parts pf a table can be effected by using the view and grant commands Privileges can be withdrawn with the revoke command
The Role of the Data Synonyms for Objects Dictionary
select name from CAROLE.student; A set of tables and views to be used by the RDBMS as a reference guide to the data create [public] synonym stored in the database files synonym_name for table | view; Every user retrieves data from views stored in the Data Dictionary create synonym student for The Data Dictionary stores: CAROLE.student; user names of those permitted to access the database names of tables, space definitions, views, indexes, drop synonym mystudent; clusters, synonyms etc rights and privileges that have been granted
3