0% found this document useful (0 votes)
36 views4 pages

Title: SQL Constraints: Database Management System

1. The lab report discusses SQL constraints including primary keys, checks, defaults, and unions. 2. Examples create tables with primary keys, insert data, and use SELECT statements to output the results of unions and union alls on the tables. 3. One example demonstrates a check constraint to ensure column P_Id is greater than 0 and prevents an invalid row from inserting.

Uploaded by

malik Arsh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views4 pages

Title: SQL Constraints: Database Management System

1. The lab report discusses SQL constraints including primary keys, checks, defaults, and unions. 2. Examples create tables with primary keys, insert data, and use SELECT statements to output the results of unions and union alls on the tables. 3. One example demonstrates a check constraint to ensure column P_Id is greater than 0 and prevents an invalid row from inserting.

Uploaded by

malik Arsh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab Report#05

Database Management System

Title: SQL Constraints

Submitted To:
Sir Shahid Ali Bhutta
Submitted By:
Muhammad Bilal
17-CP-52
Example#01:

/*table1 person table creation*/


create table personslab5
(
P_ID int not null Primary key check(P_iD>0),
LastName varchar(255) not null ,
FirstName varchar(255),
Addres varchar(255),
City varchar(255),
);
insert into personslab5
values(1,'Hansen','Ola','Timoteivn 10','Sandness');
insert into personslab5
values(2,'Svendson','Tove','Borgvn 23','Sandness');
insert into personslab5
values(3,'Pettersen','Kari','Storgt 20','Stavanger');
select * from personslab5;
Query:

/*tasks*/
/*union of table,union example*/
select FirstName from personslab5
union
select LastName from personslab5

Output:

Example#02:
1st Table Creation:
/*employee table creation*/
create table Employeelab5
(
E_ID int,
E_Name varchar(255),
);
insert into Employeelab5
values(1,'Hansen,Ola');
insert into Employeelab5
values(2,'Svendson,Tove');
insert into Employeelab5
values(3,'Svendson,Stephen');
insert into Employeelab5
values(4,'Svendson,Kari');
select * from Employeelab5;

2nd Table Creation:


/*creation of table employee norway*/
create table Employeelab_Norway
(
E_ID int,
E_Name varchar(255),
);
insert into Employeelab_Norway
values(1,'Turner,Sally');
insert into Employeelab_Norway
values(2,'Kent,Clark');
insert into Employeelab_Norway
values(3,'Svendson,Stephen');
insert into Employeelab_Norway
values(4,'Scott,Stephen');
select * from Employeelab_Norway;
Query:
/*union of tableemployee,union example*/
select E_Name from Employeelab5
union
select E_Name from Employeelab_Norway
Output:

Example#03:

Query:
/*union all of tableemployee,union example*/
select E_Name from Employeelab5
union all
select E_Name from Employeelab_Norway
Output:

Example#04:

Query:
CREATE TABLE Prson
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Addres varchar(255),
City varchar(255) DEFAULT 'Sandnes'
);
insert into Prson(P_Id, LastName, FirstName,Addres)
values(1,'Hansen','Ola','Timoteivn 10');
insert into Prson (P_Id, LastName, FirstName,Addres)
values(0,'Svendson','Tove','Borgvn 23' );
insert into Prson(P_Id, LastName, FirstName,Addres)
values(3,'Pettersen','Kari','Storgt 20' );
select * from Prson ;
Output:

Example#05:

Query:
CREATE TABLE CHECKCOMMAND
(
P_Id int NOT NULL CHECK (P_Id>0),
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Addres varchar(255),
City varchar(255)
);
insert into CHECKCOMMAND
values(1,'Hansen','Ola','Timoteivn 10','Sandness');
insert into CHECKCOMMAND
values(0,'Svendson','Tove','Borgvn 23','Sandness');
insert into CHECKCOMMAND
values(3,'Pettersen','Kari','Storgt 20','Stavanger');
select * from CHECKCOMMAND ;

Output:

You might also like