MySQL 01
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
structure.
Name of Column
ID
First_Name
Last_Name
User_ID
Salary
Type
INT (4)
VARCHAR (15)
VARCHAR (15)
CHAR (10)
FLOAT (10,2)
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
command.
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.