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

Practical 4

The document outlines a practical exercise for a Database Management System course, focusing on applying data constraints to various tables including client, product, salesman, sales_order, and sales_order_details. It includes specific requirements for creating tables with attributes, adding constraints, inserting data, and handling errors related to foreign key relationships. Additionally, it addresses altering tables and dropping constraints while observing the behavior of the database system.

Uploaded by

22bce281
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)
19 views4 pages

Practical 4

The document outlines a practical exercise for a Database Management System course, focusing on applying data constraints to various tables including client, product, salesman, sales_order, and sales_order_details. It includes specific requirements for creating tables with attributes, adding constraints, inserting data, and handling errors related to foreign key relationships. Additionally, it addresses altering tables and dropping constraints while observing the behavior of the database system.

Uploaded by

22bce281
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

Database Management System (2CS505CC23)

Practical No : 4

Aim : 1. Applying data constraints on tables


 Unique, primary key, foreign key, check, not null, default
value

1. Create the constraints as specified for all the tables.

a) Create table client (used to store client information) having


following attributes:
Column Data Size Default Attributes
Name Type
clientno varchar2 6 Primary key at column
level/first letter must
start with ‘C’ (at
column level)
name varchar2 20 Not Null
city varchar2 15
pincode number 8
state varchar2 15
baldue number 10, 5

1. b) Create table product (used to store product information)


having following attributes:
Column Data Size Defaul Attributes
Name Type t
productno varchar2 6 Primary key at table
level/first letter
must start with ‘P’
(at table level)
description varchar2 15 Not Null
profitpercent number 4, 2 Not Null
unitmeasure varchar2 10 Not Null
qtyonhand number 8 Not Null
reorderlvl number 8 Not Null
sellprice number 8, 2 Not Null, Cannot be
0
costprice number 8, 2 Not Null, Cannot be
0

1. c) Create table salesman (used to store salesman information


working for the company) having following attributes:
Column Name Data Type Size Defa Attributes
ult
salesmanno varchar2 6 Primary key at table
level /first letter
must start with ‘S’
salesmanname varchar2 20 Not Null
address1 varchar2 30 Not Null
address2 varchar2 30
city varchar2 20
pincode number 8
state varchar2 20
salamt number 8, 2 Not Null, Cannot be
0
tgttoget number 6, 2 Not Null, Cannot be
0
ytdsales number 6, 2 Not Null
remarks varchar2 60

1. d) Create table sales_order (used to store client’s orders)


having following attributes:
Column Data Size Defau Attributes
Name Type lt
orderno varchar2 6 Primary key/first letter must
start with ‘O’
clientno varchar2 6 Foreign key (at column level)
references clientno of client
table.
orderdate date Not Null
salesmann varchar2 6 Foreign key (at column level)
o references salesmanno of
salesman table.
delaytype char 1 F Delivery : part (P) / full (F)
billyn char 1
delaydate date Cannot be less than orderdate
(at table level)
orderstatu varchar2 10 Values(‘In
s Process’,’Fulfilled’,’BackOrder’,’
Cancelled’) (at column level)

1. e) Create table sales_order_details (used to store client’s orders


with details of each product ordered ) having following attributes:
Column Data Size Default Attributes
Name Type
orderno varchar2 6 Foreign key
references (at table
level) orderno of
sales_order table
productno varchar2 6 Foreign key (at table
level) references
productno of product
table
qtyordered number 8
productrate number 10, 2

2. Alter table salesman, add constraint Not Null on remarks column and
observe the behavior. Mention your remarks.

3. Insert data in all the tables as per Practical – 2 and check if any
constraint is getting violated.

4. Delete data of salesman ‘S01’ from salesman table and observe the
error. Rewrite the query for alteration of table, so that on deletion of
‘S01’ from salesman, corresponding values associated should also get
deleted.

5. Delete data of order ‘O19001’ from sales_order table and observe the
error. Rewrite the query for alteration of table, so that if you remove
‘O19001’ from sales_order, corresponding values associated should be
set to NULL.
6. Drop primary key constraint on ‘orderno’ from sales_order table.
Observe the error. Write the drop query, so that associated constraints
with ‘orderno’ also gets dropped. Check whether the constraints have
dropped from user_constraints table.

You might also like