0% found this document useful (0 votes)
2 views3 pages

SQL Assignment

The document outlines a series of lab assignments focused on creating and managing database tables for Departments, Employees, Customers, Products, and Orders, including their respective columns, data types, and constraints. It includes instructions for data entry, retrieval, and various SQL operations such as adding constraints, calculating profits, and listing customer balances. The assignments emphasize practical application of SQL in database management and querying.

Uploaded by

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

SQL Assignment

The document outlines a series of lab assignments focused on creating and managing database tables for Departments, Employees, Customers, Products, and Orders, including their respective columns, data types, and constraints. It includes instructions for data entry, retrieval, and various SQL operations such as adding constraints, calculating profits, and listing customer balances. The assignments emphasize practical application of SQL in database management and querying.

Uploaded by

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

Lab Assignment -2

1. Create a Department table with the following columns and constraints.

Column name Datatype Size Constraints


Dept_no int 2 Primary Key
D_name Varchar 10 Unique, not null
Location Varchar 10 Unique, not null
2. Enter the following data into the Department table.
Dept_ no D_name Location
10 Accounting New York
20 Research Dallas
30 Sales Chicago
40 Operations Boston

3. Retrieve all the records of the Department table.


4. Create an Employee table with the following columns and constraints.

Column name Datatype Size Constraints


Emp_no Char 4 Primary Key
E-name Varchar 10 Not null
Job Varchar 10
Mgnr Char 4
Hiredate Date Not null
Gender Char 1 Only has value either M or F
Salary Decimal 8,2 Default 0
Commission Decimal 8,2 Default 0
Dept_no int 4 References to Dept-no of department table

5. Enter the data into the Employee table.


Emp_no E-name Job Mgnr Hiredate Gender Salary Commission Dept_no
7369 Smith Clerk 7839 17-Dec-1980 M 8000 20
7499 Allen Salesman 7698 20-Feb-1981 F 16000 300 30
7521 Ward Salesman 7698 22-Feb-1981 F 12500 500 30
7566 Jones Manager 7839 02-Apr-1981 M 21750 20
7654 Martin Salesman 7698 28-Sept-1981 M 12500 1400 30
01:20:33pm
7698 Blake Manager 7839 01-May-1981 F 28500 30
2:15:40 pm
7782 Clark Manager 7839 09-Jun-1981 M 24500 10
7788 Scott Analyst 7566 09-Dec-1982 M 30000 20
7839 King President 17-Nov-1981 M 50000 10
7844 Turner Salesman 7698 08-Sept-1981 M 15000 30

6. Add a table level constraint such that commission cannot be greater than the 30% of salary after
the table has been created. Assign a user-defined constraint named ctbl_comm_gt_30_sal.
7. Add a new constraint with the name Dept_chk_loc to Department table such that Location can be
any one of the following cities:- New York, Dallas, Chicago and Boston only.
8. It has been decided that the Location of more than one department could be same. So it is required
to disable temporarily the unique constraint on location column.
9. Enable the disabled constraint on Location column of the Department table.
10. Remove the unique constraint from the Location column of the Department table.

Lab Assignment -3
1. Create a Customer table with the following columns and constraints.

Column name Datatype Size Constraints


Cust_id Char 6 Primary Key, Also start with ‘C’
Cust_name Varchar 20 Unique, not null
Address Varchar 20 Unique, not null
City Varchar 20
Pincode int 6
State Varchar 20
Bal_due Decimal 8,2
2. Enter the following data into the Customer table.
Cust_id Cust_name Address City Pincode State Bal_Due
C1001 Asnani Brothers 243, 9-B Bhopal 462024 MP 5000
C1002 Singh and Co. E-1,2 Bhopal 462020 MP 3000
C1003 Gupta Sales 100, G-Park Gurgaun 110234 HR 1000
C1004 Sinha and Sons 21, B-Park Chittorgarh 230011 RJ 7000
C1005 Arora Co. 28, 2-C Bhopal 462021 MP 3300

3. Retrieve all the records of the Customer table.


4. Create a Product table with the following columns and constraints.

Column name Datatype Size Constraints


Pro_id Char 6 Primary Key
Pro_name Varchar 20
Quantity int 5
Cost_Price Decimal 8,2
Sell_Price Decimal 8,2
5. Enter the following data into the Product table.
Pro_id Pro_name Quantity Cost_Price Sell_Price
CD-01 Phillips CD 10 2000 3000
CD-02 Samsung D100 20 2500 3200
TV-01 Samsung T101 30 10000 12000
TV-02 Samsung T222 12 12000 14000
TV-03 Phillips 1022 14 9000 12000
TV-04 Phillips2002 11 15000 18000
RF-01 Godrej-Q 25 10000 13000
RF-02 Godrej-D 23 16000 18000
RF-03 Godrej-A 12 20000 20000
6. Create an Order table with the following columns and constraints.

Column name Datatype Size


Ord_id Char 6
Ord_date Date
Cust_id Char 6
Pro_id Char 6
Quantity Decimal 5
Primary Key ( Ord-Id+Ord_date+cus_id+Pro_id)

Ord_id Ord_date Cust_id Pro_id Quantity


O101 11-feb-2008 C1001 CD-01 10
O102 12-feb-2008 C1001 TV-01 20
O103 11-feb-2008 C1002 RF-01 12
O103 11-feb-2008 C1002 TV-04 15
O104 25-mar-2009 C1003 TV-03 11
O104 25-mar-2009 C1003 RF-02 5
7. Insert the following values to the Order table.

8. Apply UNIQUE constraint on cut_id + pro_id on the Order table.


9. Define FOREIGN KEY on cust_id of the Order table referring to cust_id of the Customer table.
10. Define FOREIGN KEY on pro_id of the Order table referring to pro_id of the Product table.
11. List the names of all the customers whose balance due is more than RS 4000.
12. For all the product display the product name along with net profit of selling price, cost price.
13. Count the total number of orders from order table.
14. Count the customer wise number of order.
15. Calculate profit earned on each order.
16. Calculate the average selling price of all the product.
17. Calculate the max and min quality of products, which have been ordered and display them as
‘max_qty” and “min_qty” respectively.
18. Display the order placed during 2008.
19. List the year wise number of order placed.
20. Display the customer with maximum due balance.
21. Display the customer with minimum due balance.
22. Display the top 3 customer with maximum due balance.

You might also like