Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
19. What is the difference among super, primary, candidate and foreign keys?
A super key of a table is a set of attributes which can determine all other attribute values in the give
table. In other words, set of attributes which can identify the records uniquely from the table.
No two rows can have the same value of super key attributes.
A Candidate key is minimal superkey. i.e. Minimal set of attributes that can determine all attribute
values in the given table.
A Primary Key is one of the candidate keys. One of the candidate keys is selected as most important and
becomes the primary key. There cannot be more that one primary key in a table. Foreign
key is a field (or collection of fields) in one table that uniquely identifies a row of another table.
In the above example, Student table gives information about students. Branch table gives information
about existing branches in the college. The bname values that come in Student table should be there in
Branch table (in other words, the bname value of any record in student table identifies a row of Branch
table uniquely).
Create table Branch(bname varchar(20) primary key, yoe number(4), intake number(3));
Create table Student(regdno varchar(10) primary key, name varchar(20), age number(2),
bname varchar(20), perc number(5,2), foreign key(bname) references Branch);
Note:
Datatypes in Oracle: integer, number, char, varchar, date, blob
Difference between char() and varchar(): char() is a fixed length character string, where as varchar() is a
variable length character string.
Blob – Blob stands for Binary large object. It is used to store images, files etc.
In the above example, the table RESERVES has 2 foreign keys. One is (sid) references Sailors table &
another foreign key is (bid) references Boats table.
23. What is the difference between primary key and unique constraints?
Primary key cannot have NULL value, the unique constraints can have NULL values.
There is only one primary key in a table, but there can be multiple unique constrains.
Primary Key = Unique + Not Null
28. What is the difference between TRUNCATE, DELETE & DROP commands?
Truncate command removes all the records from the given table. Delete command is used delete/remove
records that satisfy the given condition. Whereas, Drop command removes the table.
The difference between TRUNCATE and DELETE is that the action of TRUNCATE can’t be rolled back,
whereas the action of DELETE can be rolled back.
Further Explanation:
The DELETE command is used to remove rows from a table. A WHERE clause can be used
to remove only some rows. If no WHERE condition is specified, all rows will be removed. After
performing a DELETE operation you need to COMMIT or ROLLBACK the transaction to make the
change permanent or to undo it. Note that this operation will cause all DELETE triggers on the table to
fire.