Вы находитесь на странице: 1из 3

MySQL 01

Note 1:Since MySQL automatically commits (saves) after every insertion, updation or
deletion, we need to set autocommit off in the beginning by:
set autocommit=0;
Note 2:SQL commands as well as table names, field names,data types etc are NOT case
sensitive,but the string literals within single quotes are.
1)Create a database Company.Inside this database,create a table Employee having the following
Name of Column

INT (4)
CHAR (10)
FLOAT (10,2)

2)Use DESCRIBE command to see the table structure.

3)Populate table with the 3 records below using the insert command.
4)For the fourth record enter only id as 4 and first name as Shankar using implicit method.
5)For the fifth record enter only id as 5, last name as 'Buddha' and user id as 'GBuddha' using
explicit method.
6)Display all the information in the table.The table should have the following data.

7)Notice that the 4th and 5th records have incomplete information.For the record with id=4,update
last name with 'Giri',user_id with 'SGiri' and salary with 7000.
8)For the record with last_name as 'Buddha',update first name with 'Gautam' and salary with 2000.
9)Save the changes to the employee table and display the data in the table.It should look as
shown below.

10) For the employee having id 3,modify the Last Name, , to 'Jain' and user id to 'SJain'.Verify using
select command.
11)Modify the Salary and increase it by 1000, for all who get salary less then 5000.Verify using
select command.
12)Delete the employee record having First_Name as Siddharth.Verify using select command.
13)Make the changes permanent and display the data in the table.It should look as shown below.

14)Delete all the records in the table.(Do not truncate the table or drop the table).Verify using
select command.
15)Undo the above step and again verify using select command.
16)Add a column to the table telephone which is of type long.Use describe command to verify.Also
display the data in the table.The outputs should resemble what is displayed below.

17)Assume that all these 4 employee are staying in the same flat.Populate the telephone field with
the number 3444444 for all the employees.Verify using select.
18)Delete the column user_id.Confirm that the column has been deleted with the describe
19)Undo the column deletion.Check whether the column has been brought back.If not,why?
20)Display the structure of the table.Change the width the of the first_name field to 10.Also
change the width of the last_name field to 20.Once again use the describe command to verify.
21)Create a copy of the employee table with the name employee2.Display the contents of both the
tables using the select command.
22)Create a copy of the employee table with the name employee3,but only having fields id,first
name and telephone.Display the contents of employee3 using the select command.Employee3
ahould resemble figure below.

23)Delete table employee2 using drop command.Verify using select command.

24)Rename employee3 as temp.Verify using select command.
25)Delete the records in temp table using truncate command.Verify using select command.
26)Try to undo the truncate operation.
27)Is the temp table deleted.Check using the describe command.
28)Display all the records in the employee table and the temp table.Also display the structure of
both the tables.
29)Insert a record having the fields id,first_name and telephone number of Shankar from employee
into temp.Verify that the record has been copied by using the select command with temp table.The
temp table should look as shown below.

30)Drop both the tables,drop company database and quit.