0% found this document useful (0 votes)
23 views

It Project For Class 12 1

File

Uploaded by

batthrahul1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

It Project For Class 12 1

File

Uploaded by

batthrahul1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

lOMoARcPSD|38132553

SQL
QUERIES

Downloaded by Nitika Bimrah ([email protected])


lOMoARcPSD|38132553

1. Write down syntax and mysql program to create a database STUDENT and its
OUTPUT.

AIM

To write a MYSQL code to create a database STUDENT listing out its SYNTAX, and
its OUTPUT.

SYNTAX

PROGRAM

mysql> create database student;

OUTPUT

Downloaded by Nitika Bimrah ([email protected])


lOMoARcPSD|38132553

2.Write down syntax and mysql program to delete a database STUDENT and its
OUTPUT.

AIM

To write a MYSQL code to delete a database STUDENT listing out its SYNTAX, and
its OUTPUT.

SYNTAX

PROGRAM

mysql> drop database student;

OUTPUT

Downloaded by Nitika Bimrah ([email protected])


lOMoARcPSD|38132553

3.Write down a mysql program to create a table TEACHER with the following field
names given below and its OUTPUT.

⚫ Teacher_ID,
⚫ First_Name,
⚫ Last_Name,
⚫ Gender,
⚫ Salary,
⚫ Date_of_Birth,
⚫ Dept_No

AIM
To write a mysql code to create a table TEACHER with the given field names

⚫ Teacher_ID,
⚫ First_Name,
⚫ Last_Name,
⚫ Gender,
⚫ Salary,
⚫ Date_of_Birth,
⚫ Dept_No

and its OUTPUT.

PROGRAM

mysql> CREATE TABLE TEACHER


→(
→ Teacher_ID INTEGER,
→ First_Name VARCHAR(20),
→ Last_Name VARCHAR(20),
→ Gender CHAR(1),
→ Salary DECIMAL(10,2),
→ Date_of_Birth DATE,
→ Dept_No INTEGER
→);

OUTPUT

Downloaded by Nitika Bimrah ([email protected])


lOMoARcPSD|38132553

4. Write down mysql program to show the databases and tables created?

AIM

To write a mysql command to show the databases and tables and its output.

PROGRAM
mysql> show databases;

OUTPUT

PROGRAM
mysql> show tables;

OUTPUT

Downloaded by Nitika Bimrah ([email protected])


lOMoARcPSD|38132553

5. Write a mysql program to list out the field name Teacher_ID,


First_Name, Last_Name, Gender, Salary, Date_of_Birth, Dept_No
along with its field type and constraints for the table TEACHER in the
database STUDENT.

AIM
To write a mysql program to list out the field name Teacher_ID, First_Name,
Last_Name, Gender, Salary, Date_of_Birth, Dept_No
along with its field type and constraints for the table TEACHER in the database
STUDENT

PROGRAM
mysql > use student;
Database changed

mysql > desc teacher;

OUTPUT

Downloaded by Nitika Bimrah ([email protected])


lOMoARcPSD|38132553

Write down mysql program to set a default value for the field SALARY as
6.
30000 to the table name TEACHER whose field names are listed below
⚫ Teacher_ID,
⚫ First_Name,
⚫ Last_Name,
⚫ Gender,
⚫ Salary,
⚫ Date_of_Birth,
⚫ Dept_No

AIM

To write a mysql command to set a default value for the field SALARY as
30000 in table TEACHER.

PROGRAM

mysql > desc teacher;

mysql > ALTER TABLE TEACHER ALTER SALARY SET DEFAULT 30000;

OUTPUT

Downloaded by Nitika Bimrah ([email protected])


lOMoARcPSD|38132553

7.Write a mysql command to INSERT VALUES INTO table TEACHER in its field
Teacher_ID, First_Name, Last_Name, Gender, Salary, Date_of_Birth, Dept_No

AIM

To write a mysql command to INSERT VALUES INTO table TEACHER in its field
Teacher_ID, First_Name, Last_Name, Gender, Salary, Date_of_Birth, Dept_No

PROGRAM

mysql > INSERT INTO Teacher (Teacher_ID, First_Name, Last_Name,


Gender, Salary, Date_of_Birth, Dept_No) VALUES(101,"Shanaya", "Batra",
'F', 50000, '1984-08-11', 1);

OUTPUT

Downloaded by Nitika Bimrah ([email protected])


lOMoARcPSD|38132553

8.Write a mysql command to display the details of a Teacher whose


Teacher_ID=101.

The field names in Teacher table is listed below.

⚫ Teacher_ID,
⚫ First_Name,
⚫ Last_Name,
⚫ Gender,
⚫ Salary,
⚫ Date_of_Birth,
⚫ Dept_No

AIM

To write a mysql command to display the details of Teacher_ID=101 in table


TEACHER with its field names listed below.

⚫ Teacher_ID,
⚫ First_Name,
⚫ Last_Name,
⚫ Gender,
⚫ Salary,
⚫ Date_of_Birth,
⚫ Dept_No

PROGRAM

mysql > SELECT * FROM TEACHER WHERE Teacher_ID=101;

OUTPUT

Downloaded by Nitika Bimrah ([email protected])


lOMoARcPSD|38132553

9. Write a mysql command to UPDATE the details of Salary as 55000 in Teacher


table whose Teacher_ID=101.

The field names in Teacher table is listed below.

Teacher_ID, First_Name, Last_Name, Gender, Salary, Date_of_Birth, Dept_No

AIM

To write a mysql command to display the UPDATED details of Salary as 55000


for Teacher_ID=101 in table TEACHER with its field names listed below.

Teacher_ID, First_Name, Last_Name, Gender, Salary, Date_of_Birth, Dept_No

PROGRAM

mysql> UPDATE Teacher SET Salary=55000 WHERE Teacher_ID=101;

OUTPUT

10

Downloaded by Nitika Bimrah ([email protected])


lOMoARcPSD|38132553

10. Write a mysql command to find the following using AGGREGATE FUNCTIONS
in Table Teacher. The field names in Teacher table is listed below.
Teacher_ID, First_Name, Last_Name, Gender, Salary, Date_of_Birth, Dept_No

(i) Calculate the sum of salary given to the Teachers and name it as Total_Salary.
(ii) Calculate the maximum and minimum salary of the Teacher and name it as
Max_Salary and Min_Salary.
(iii) Calculate the total number of Teachers whose salary is >40000.

AIM

To write mysql command using AGGREGATE FUNCTIONS to


(i) Calculate the sum of salary given to the Teachers and name it as Total_Salary.
(ii) Calculate the maximum and minimum salary of the Teacher and name it as
Max_Salary and Min_Salary.
(iii) Calculate the total number of Teachers whose salary is >40000.
11

Downloaded by Nitika Bimrah ([email protected])


lOMoARcPSD|38132553

PROGRAM
mysql > SELECT SUM(Salary) AS Total_Salary FROM Teacher;

OUTPUT

PROGRAM
mysql > SELECT MAX(Salary) AS Max_Salary, MIN(Salary) AS Min_Salary
FROM Teacher;

OUTPUT

PROGRAM
mysql > SELECT COUNT(Salary) FROM Teacher WHERE Salary > 40000;

OUTPUT

12

Downloaded by Nitika Bimrah ([email protected])

You might also like