Experiment No. 4 - DBMS Lab Final
Experiment No. 4 - DBMS Lab Final
a. Nested Query
A nested query is a select query that is nested inside a SELECT,UPDATE,INSERT, or
DELETE SQL query.
Example:
SELECT Model FROM Product WHERE ManufacturerID IN (SELECT ManufacturerID FROM
Manufacturer WHERE Manufacturer = 'Dell')
b. SQL Constraints
SQL constraints are used to specify rules for data in a table Constraints are used to limit the
type of data that can go into a table. This ensures the accuracy and reliability of the data in
the table. If there is any violation between the constraint and the data action, the action is
aborted.
Constraints can be column level or table level. Column level constraints apply to a column,
and table level constraints apply to the whole table.
7. INDEX - Used to create and retrieve data from the database very quickly
By default, a column can hold NULL values. The NOT NULL constraint enforces a column
to NOT accept NULL values.
Example:
The UNIQUE constraint ensures that all values in a column are different. Both the UNIQUE
and PRIMARY KEY constraints provide a guarantee for uniqueness for a column or set of
columns.
Example-
The PRIMARY KEY constraint uniquely identifies each record in a database table. Primary
keys must contain UNIQUE values, and cannot contain NULL values.
Example-
A FOREIGN KEY is a key used to link two tables together. A FOREIGN KEY is a field (or
collection of fields) in one table that refers to the PRIMARY KEY in another table.
Example-
The CHECK constraint is used to limit the value range that can be placed in a column. If you
define a CHECK constraint on a single column it allows only certain values for this column.
Example-
Example-
CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
City varchar(255) DEFAULT 'Sandnes' );
b) SQL Views
In SQL, a view is a virtual table based on the result-set of an SQL statement. A view contains
rows and columns, just like a real table. The fields in a view are fields from one or more real
tables in the database.
Example-
SQL QUERIES:
Creation of tables.
Student Table.
Book Table
Transaction Table.
2. Write SQL command to add a new field DOB in the STUDENT table.
Insertion in Student..
Insertion in book..
Insertion in Transaction..
e). To display all the books which have been issued so far.
f). To display all the books which have not been issued so far.
g). To display all the students of 4th year CSE branch who are staying in the
hostel.
h). To display the student’s names who have not returned the books issued to them.
i). To display the students name who have been issued DBMS book by Korth.
j). To display the students who have not issued any book so far.
k). To display the students who have been issued at least one book.
l). To display the title of the second costliest book.
m). To display the students who have not returned the book more than 6
weeks.
o). To display the students of 4th year from CSE branch who have been issued Graphics
book(s) for more than 15 days , which have not been returned.