0% found this document useful (0 votes)
7 views

SQL_LABSHEET

Uploaded by

Kiran Pathak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

SQL_LABSHEET

Uploaded by

Kiran Pathak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Database Management System

Lab Work

Lab 4:
Write DDL statements to create table for entity customer(cid,name,age,address)
cid: stores integers value and is unique
name : stores maximum of 30 characters
dob: stores date and time value
address: stores at most 30 characters and only Ktm,Bkt, amd Ltp can be
assigned
Solution:

CREATE table customer

(cid int PRIMARY KEY,

name varchar(30),

dob datetime,

address varchar(30) CHECK (address='Ktm' OR address='Bkt' OR

address='Ltp'));

Lab 5:

Write DDL statements for the following table ‘Student’

Name of Attributes Data types Constraints

Sid Character Primary Key

Name Character Not null

Login Character UNIQUE

Age Integer Default 18 yrs

GPA Real In between 0 and 4


Sloution :

CREATE table student

(sid char PRIMARY KEY,

name char not null,

login char UNIQUE,

age int DEFAULT 18,

gpa real CHECK (GPA Between 0 and 4));

Lab 6:

Write the SQL statement to construct following tables and relationship

Author(aid,name,age,gender,address)

Writes(aid,bid,publishdate,bookname,ISBN)

Constraints for table

a. Name should not be more than 20 charcters long

b. Age should be more than 10

c. Default gender should be ‘unknown’

d. ISBN canot be null

CREATE table Author

(aid int primary key,

name varchar(20),

age int,

gender varchar(20)default 'unkown',


address varchar(20)

CHECK(age>10));

CREATE table writes

(bid int PRIMARY KEY,

publishdate datetime,

bookname varchar(20),

ISBN int not null,

aid int,

foreign key(aid) references author(aid));

lab 7:

Write DDL statements for the following

Table name Attributes Types Constraints

Empid Varchar Primary key

Empname Varchar Not null

Employees Gender Varchar Value must be “M”, “F” or “O”

Age Number Age must be >16


Solution;

Create table Employees

(Empid varchar(20) primary key,

Empname varchar(20) not null,

Gender varchar check(gender='M' or gender='F' or gender='O'),

Age int check(age>16));

Or
Create table Eemployee

(Empid varchar(20) primary key,

Empname varchar(20) not null,

Gender enum('m','f','o') not null,

Age int check(age>16));

Compiled by:
LB Gurung
[email protected]

You might also like