SQL Program 1
1. Write the query to create a table ‘Student’ with the following fields.
Ad_No Integer Primary Key, Name VarChar(20),
Class Char(15), Mark Integer
2. Insert the following six records into the table.
Ad_No Name Class Mark
786 Anoop +1 Commerce 75
675 Manu +1 Commerce 50
452 Jaffar +2 Commerce 40
384 Mujeeb +2 Science 80
235 Ranjith +2 Commerce 86
573 Anand +2 Commerce 65
3. Write Query to display all the details.
4. Display the details of the students from the class ‘+2 Commerce’
5. Increase the mark of all students by ‘5’
6. Display the table in the order of ‘Ad_No’
7. Delete the table ‘Student’
Queries
1. MySQL> Create Table Student
(Ad_No Int Primary Key, Name VarChar(20),
Class Char(25), Mark Int) ;
2.
a) MySQL> Insert Into Student Values (786, ‘Anoop’, ‘+1 Commerce’, 75);
b) MySQL> Insert Into Student Values (675, ‘Manu’, ‘+1 Commerce’, 50);
c) MySQL> Insert Into Student Values (452, ‘Jaffar’, ‘+2 Commerce’, 40);
d) MySQL> Insert Into Student Values (384, ‘Mujeeb’, ‘+2 Science’, 80);
e) MySQL> Insert Into Student Values (235, ‘Ranjith’, ‘+2 Commerce’, 86);
f) MySQL> Insert Into Student Values (573, ‘Anand’, ‘+2 Commerce’, 65);
Page 1 of 6
3. MySQL> Select * From Student;
4. MySQL> Select * From Student where Class = ‘+2 Commerce’;
5. MySQL> Update Student Set Mark = Mark + 5 ;
6. MySQL> Select * From Student Order By Ad_No ;
7. MySQL> Drop Table Student ;
SQL Program 2
1. Write the query to create a table ‘Deposit’ with the following fields.
AccNo Integer Primary Key, BName Char(20), Name VarChar (25),
Balance Integer Not Null
2. Insert the following six records into the table.
AccNo BName Name Balance
2246 Nilambur John 12000
3648 Wandoor Azees 18000
4376 Manjeri Varghese 25000
7564 Kalikav Ashok 22000
2835 Nilambur Muhammed 28000
3879 Wandoor Santhosh 20000
3. Sort the table in the order of ‘Balance’
4. Display the AccNo, Name and Balance having Balance >= 22000.
5. Insert a new column in the table as given below
“Ph_No Integer”
6. Change the name of the customer into ‘Jacob’ whose AccNo=4376.
Page 2 of 6
Queries
1. MySQL> Create Table Deposit (AccNo Int Primary Key, Bname Char(20),
Name VarChar(25), Balance Int Not Null);
2.
a) MySQL> Insert Into Deposit Values (2246, ‘Nilambur’, ‘John’, 12000) ;
b) MySQL> Insert Into Deposit Values (3648, ‘Wandoor’, ‘Azees’, 18000) ;
c) MySQL> Insert Into Deposit Values (4376, ‘Manjeri’, ‘Varghese’, 25000) ;
d) MySQL> Insert Into Deposit Values (7564, ‘Kalikav’, ‘Ashok’, 22000) ;
e) MySQL> Insert Into Deposit Values (2835, ‘Nilambur’, ‘Muhammed’, 28000) ;
f) MySQL> Insert Into Deposit Values (3879, ‘Wandoor’, ‘Santhosh’, 20000) ;
3. MySQL> Select * From Deposit Order By Balance ;
4. MySQL> Select AccNo, Name, Balance From Deposit Where Balance >= 22000 ;
5. MySQL> Alter Table Deposit Add (Ph_No Int) ;
6. MySQL> Update Deposit Set Name = ‘Jacob’ Where AccNo= 4376 ;
SQL Program 3
1. Create a table ‘Emp’ with the following fields
Emp_id Integer, EmpName Char(25) , Department Char(20), Designation Char(20),
Salary Integer.
2. Enter the details as follows
Emp_Id EmpName Department Designation Salary
32475 Mathews Education Clerk 12000
48763 Arun Agriculture Peon 8000
76329 Hashim Health Nurse 13000
12495 Manoj Education Teacher 17000
24336 Suresh Finance Accountant 20000
64329 Nasar Police Constable 14000
Page 3 of 6
3. Sort the table in the descending order of ‘Salary’
4. Display the Name and Department of the employees having ‘Salary >= 15000’
5. Display the Maximum of the salaries.
6. Find the total of the salaries.
Queries
1. MySQL> Create Table Emp (Emp_id Int, EmpName Char(20),
Department Char (20), Designation Char (20), Salary Int) ;
2.
a) MySQL> Insert Into Emp Values(32475, ‘Mathew’, ‘Education’, ‘Clerk’, 12000);
b) MySQL> Insert Into Emp Values(48763, ‘Arun’, ‘Agriculture’, ‘Peon’, 8000);
c) MySQL> Insert Into Emp Values(76329, ‘Hashim’, ‘Health’, ‘Nurse’, 13000);
d) MySQL> Insert Into Emp Values(12495, ‘Manoj’, ‘Education’, ‘Teacher’, 17000);
e) MySQL> Insert Into Emp Values(24336, ‘Suresh’, ‘Finance’, ‘Accountant’, 20000);
f) MySQL> Insert Into Emp Values(64329, ‘Nasar’, ‘Police’, ‘Constable’, 14000);
3. MySQL> Select * From Emp Order By Salary Desc ;
4. MySQL> Select Name, Department from Emp Where Salary >= 15000;
5. MySQL> Select Max(Salary) From Emp;
Output
Max(Salary)
20000
6. MySQL> Select Max(Salary) Total From Emp;
Output
Total
84000
Page 4 of 6
SQL Program 4
1. Create a table ‘Salary’ with the following fields.
SlNo Integer, Name VarChar(25), Sex Char(6), Designation Char(6)
Branch Char(15), Salary Integer.
2. Insert the following records into ‘Salary’
Name Sex Designation Branch Salary
SlNo
1 Varun Male Sales man Kannur 7000
2 Geetha Female Sales girl Calicut 8000
3 Naveen male Manager Kannur 16000
Malappura
4 Rasheed male Accountan 14000
m
5 Sajitha Female Sales girl Calicut 7500
6 Vinod Male Accountent Kannur 13000
3. Display the details of staff from the branch ‘kannur’
4. Find the number of male staff in the table
5. Display the maximum of the salaries
6. Display the total of the salaries
7. Sort the table in the order of name
Queries
1. MySQL> Create Table Salary
(SlNo Int, Name Varchar(25), Sex Char(6),
Designation Char(20), Branch char(15), salary Int);
2.
a) MySQL> Insert Into Salary Values (1, ‘Varun’, ‘Male’, ‘Salesman’, ‘Kannur’, 7000)
;
b) MySQL> Insert Into Salary Values (2, ‘Geetha’, ‘Female’, ‘Sales girl’, ‘calicut’,
8000) ;
Page 5 of 6
c) MySQL> Insert Into Salary Values (3, ‘Naveen’, ‘Male’, ‘Manager’, ‘Kannur’,
16000) ;
d) MySQL> Insert Into Salary Values (4, ‘Rasheed’, ‘Male’, ‘Accountant’,
‘Malappuram’, 14000) ;
e) MySQL> Insert Into Salary Values (5, ‘Sajitha’, ‘Female’, ‘Salesgirl’, ‘Calicut’,
7500) ;
f) MySQL> Insert Into Salary Values (6, ‘Vinod’, ‘Male’, ‘Accountant’, ‘kannur’,
13000) ;
3. MySQL> Select * from Salary where Branch = ‘Kannur’ ;
4. MySQL> Select Count (Sex) From Salary Where Sex = ‘Male’ ;
Output
Count (Sex)
5. MySQL> Select Max(Salary) From Salary ;
Output
Max (Salary)
16000
6. MySQL> Select Sum (Salary) from Salary ;
Output
Sum (Salary)
65500
7. MySQL> Select * From Salary Order By Name ;
Page 6 of 6