SQL Assignment
SQL Assignment
PROFESSIONAL STUDIES
1 Assignment 1
- To write SQL queries to create table and insert data
2 Assignment 2
To write SQL queries using select command
3 Assignment 3
To write SQL queries using aggregate functions
4 Assignment 4
To create a table with constraints
5 Assignment 5
To write SQL queries for select and update command
6 Assignment 6
To write SQL queries with alter command
7 Assignment 7
To write SQL queries on Create table command
Insert command
Select command
Modify command
Delete command
Using different mathematical functions
8 Assignment 8
To write SQL queries on Create table command
Insert command
Select command
Modify command
Delete command
Using different mathematical functions
INDEX
SQL
Assignment 1
a. Write an SQL command that will create a table named Test1 with the following fields
and types: idno NUMERIC (10), fname VARCHAR (24), address VARCHAR (30),
age NUMERIC (10), giftvalue NUMERIC (10,2).
b. Write an SQL query to display all the records where age >40
d. Write an SQL query to display Fname, Age, Gift where Age > 35 from the table
f. Write an SQL query to display all record where Gift > 200 or Age >20
d. Write a query to count the number of candidates whose age in more than 30.
Assignment 4: Constraints
a. Create a table “Employee” with the following specifications
Field name Data type
EMPID INT, Primary Key
DEPT VARCHAR (5)
EMPNAME CHAR (15), Not Null
ADDRESS VARCHAR (30)
SALARY NUMERIC (7), Salary>=7000
d. Name the employees and their department whose salaries are greater than 12000.
Update Employee
Set DEPT =“AD01”
Where EMPNAME “Susan”;
Update Employee
Set Salary=Salary*1.2
Where DEPT = “AD01”;
i. Name the employee in department RD03 who lives in Park Avenue.
Assignment 6: Alter
Create a table Student1 with the following structure:
Roll no number 3
Name varchar 20
Marks number 6
Assignment 7
Write SQL queries for the following:
a. To create a table Client Details with the following specifications.
City Varchar 20
State Varchar 20
Insert into Client Details (Client No, Name, City, State, Pin Code, Bal_due)
Values
(“C00001", "Ramesh Kumar", "Mumbai", "Maharashtra", "400054", "15000”);
Insert into Client Details (Client No, Name, City, State, Pin Code, Bal_due)
Values
(“C00002", "Vandana Saitwal", "Madras", "Tamil Nadu", "780001", "0”);
Insert into Client Details (Client No, Name, City, State, Pin Code, Bal_due)
Values
(“C00003", "Pramada Jaiswal", "Mumbai", "Maharashtra", "400057", "5000”);
Insert into Client Details (Client No, Name, City, State, Pin Code, Bal_due)
Values
(“C00004", "Rukmini", "Delhi", "Delhi", "100001", "2000”);
c. To display the names of all the clients.
d. To display the maximum balance due under the heading “Max Bal_due”.
Assignment 8
1. Write an SQL command that will create a table named Friend with the following fields
and types: idno NUMERIC (10) PRIMARY KEY, fname VARCHAR (24), address
VARCHAR (30), age INT NOT NULL, giftvalue NUMERIC (10,2).
Create table Friend
(Idno numeric (10) Primary Key, fname varchar (24), address varchar (30),
age int Not Null, giftvalue numeric (10,2));
2. Insert the following items in the table you have created
Idno FName Address Age Giftvalue
5. Write an SQL query that will insert a complete record into the Friend table with these
values for the respective fields: '123', 'Tasmanian Devil', 'Tasmania', 23, 29.99.
Insert into Friend (Idno, fname, address, age, giftvalue)
Values
(“123”, “Tasmanian Devil”, “Tasmania”, “23”, “29.99”);
6. Write an SQL query to insert a record with idno as 21, name as Urvashi, address as Delhi.
Insert into Friend (Idno, Fname, Address, Age, Giftvalue)
Values
(“21", "Urvashi", "Delhi", "30", "450”);
9. Write an SQL query that will update the giftvalue to 49.99 for all people in the Friend
table who are 31 and older.
Update Friend
Set Giftvalue="49.99"
Where age>="31";
10. Write an SQL query that will add a new field/column ‘City’ to the Friend table. You can
choose its type and size.
Alter table Friend
Add City char (17);
11. Write an SQL query to delete the field ‘City’ that you added in the Friend table.
Alter table Friend
Drop Column City;
12. Write an SQL query to insert a record with name Ram and other details of your choice.
Insert into Friend (Idno, Fname, Address, Age, Giftvalue)
Values
(“23", "Ram", "Greater Kailash 75", "57", "567”);
13. Write an SQL query to display fname and age of all the records.
Select Fname, age from Friend;
14. Write SQL query to add the age of all records.
Select sum (age) from Friend;
15. Write a query to average of the cost of gifts.
Select avg (giftvalue) from Friend;
16. Write a query to display the name and age of the youngest member
Select Fname, min(age) from Friend;
17. Write a query to count the number of candidates whose age is more than 30 years.
Select count (Fname) from Friend where age> "30”;
18. Write a query to find the name and cost of the costliest gift.
Select Fname, max (giftvalue) from Friend;
19. Write an SQL query that will delete all records from the Friend table where the giftvalue
is over 100.
Delete from Friend
Where Giftvalue>100;