SAMPLE
1. Creation of a database using mysql command.
AIM: Write down syntax and mysql program to create a database SCHOOL.
Syntax: CREATE DATABASE databasename;
Program:
mysql> CREATE DATABASE SCHOOL;
2. Creation of a table using mysql command.
AIM:
a. Write down a mysql program to create a table Department with following field names – Dept_ID
and Dept_Name.
b. Write down a mysql program to create a table Teacher with following field names - Teacher_ID,
First_Name, Last_Name, Gender, Salary, Date_of_Birth, Dept_No.
Syntax: CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... );
Program (a):
mysql> CREATE TABLE DEPARTMENT
-> (DEPT_ID INT(2),
-> DEPT_NAME VARCHAR(30)
-> PRIMARY KEY (DEPT_ID));
Program (b):
mysql> CREATE TABLE TEACHER
-> (TEACHER_ID INT(3),
-> FIRST_NAME VARCHAR(30),
-> LAST_NAME VARCHAR(30),
-> GENDER VARCHAR(1),
-> SALARY INT(6),
-> DATE_OF_BIRTH DATE,
-> DEPT_NO INT(2),
-> PRIMARY KEY (TEACHER_ID));
SAMPLE
3. Show the database and tables created in mysql.
AIM: Write down a mysql program to show all the tables created in SCHOOL database.
Program:
mysql> Show Tables;
OUTPUT:
4. List out the field name along with its field type and constraints for a table.
AIM: Write down a mysql program to display the details of DEPARTMENT and TEACHER Tables.
Syntax: Describe tablename:
OUTPUT:
SAMPLE
5. INSERT VALUES INTO the table.
AIM: Write a mysql command to INSERT VALUES INTO table Department and Teacher.
Syntax: INSERT INTO table_name VALUES (value1, value2, value3, ...)
OUTPUT:
6. UPDATE the details of a field in a Table based on a given condition.
AIM: Write a mysql command to UPDATE the details of Salary as 55000 in Teacher table whose
Teacher_ID=101.
Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
SAMPLE
Program:
mysql> UPDATE TEACHER
-> SET SALARY=55000 WHERE TEACHER_ID=101;
OUTPUT:
7. SQL queries - Display the details of a field in a Table based on a given condition.
Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
i. To find the names of all teachers earning more than 50000.
ii. To display Teacher_ID, First_Name,Last_Name and Dept_No of teachers who belongs to
department number 4 or 9.
SAMPLE
iii. To list all the Department numbers corresponding to departments having male teachers without
any repetition in the output.
iv. To retrieve names of all the teachers starting from letter 'A'.
v. To retrieve names of all the teachers having 6 characters in the first name and starting with 'S'.
vi. To list the names of all the Departments in the descending order of their names.
SAMPLE
vii. To retrieve the names and department numbers of all the teachers ordered by the Department
number and within each department ordered by the names of the teachers in descending order.
viii. To retrieve all the details of those employees whose last name is not specified.
8. Aggregate Functions
i. To find the maximum and minimum salary.
SAMPLE
ii. To count the number of teachers earning more than Rs 40000.
iii. To retrieve the number of teachers in “Computer Science” Department.
iv. To display Teacher name, current salary and a 10% increase in the salary for those teachers who
belongs to Department number 4.