12 IP Worksheets MYSQL
12 IP Worksheets MYSQL
12 IP Worksheets MYSQL
My SQL Worksheet-1
(DDL – Database Related commands)
1. If a database "Employee" exists, which MySql command helps you to start working in that
database?
2. Write MySql command will be used to open an already existing database "LIBRARY".
3. Write MySql command to open an existing database.
4. What does SQL stand for? What is MySQL?
5. Write two examples of DBMS software.
6. Sharmila wants to make the database named ‘COMPANY’ active. Write MySQL commands for it.
7. What is MySQL ?
8. What is the relationship between SQL and MySQL ?
9. Mention any two example of common Database Management System.
10. Suggest Archana suitable command for the following purpose:
i. To display the list of the database already existing in MySQL.
ii. To use the database named City.
iii. To remove the pre-existing database named Clients.
11. Write the command to display the name of the active database.
12. Write the command to create a new database “School”
Informatics Practices
My SQL Worksheet-2
(DDL – Table Related commands excluding Alter table)
1. Write an SQL query to create the table 'Menu' with the following structure:
2. Can a table have multiple primary keys? Can it have multiple foreign keys?
3. In a Student table, out of Roll Number, Name, Address which column can be set as Primary key and
why?
4. Ms. Mirana wants to remove the entire content of a table "BACKUP" alongwith its structure to release
the storage space. What MySql statement should she use ?
5. Write MySql command to create the Table STOCK including its Constraints.
Table STOCK :
6. Write one similarity and one difference between CHAR and VARCHAR data types.
7. Saumya had previously created a table named ‘Product’ in a database using MySQL. Later on she
forgot the table structure. Suggest her suitable MySQL command through which she can check the
structure of the already created table.
8. Roli wants to list the names of all the tables in her database named ‘Gadgets’. Which command (s)
she should use to get the desired result.
9. Name the SQL commands used to :
(i) Physically delete a table from the database.
(ii) Display the structure of a table.
1
SAI SHREE INTERNATIONAL ACADEMY, RATLAM
10. Write one similarity and one difference between UNIQUE and PRIMARY KEY constraints.
11. An attribute A of datatype varchar(20) has the value “Amit” . The attribute B of datatype char(20)
has value ”Karanita” . How many characters are occupied in attribute A ? How many characters are
occupied in attribute B?
12. Mrs. Sharma is the classteacher of Class ‘XII A’ She wants to create a table ‘Student’
to store details of her class.
i) Which of the following can be the attributes of Student table?
a) RollNo b) “Amit” c) Name d) 25
ii) Name the Primary key of the table ‘Student’. State reason for choosing it.
13. Write SQL query to create a table ‘Player’ with the following structure:
14. Anita has created the following table with the name ‘Order’.
(i) What is the data type of columns OrderId and OrderDate in the table Order ?
(ii) Anita is now trying to insert the following row :
2
SAI SHREE INTERNATIONAL ACADEMY, RATLAM
i. Name the column that might have a Primary Key constraint. Justify your answer.
ii. Name the column that might have a Unique constraint. Justify your answer.
17. “ABC” Event Management Company requires data of events that are to be organized. Write SQL query
to create a table ‘Event’ with the following structure :
Informatics Practices
My SQL Worksheet-3
(DDL – Alter Table commands)
1. Sahil created a table in Mysql. Later on he found that there should have been another column in the
table. Which command should he use to add another column to the table?
2. While creating a table 'Customer' Simrita forgot to set the primary key for the table. Give the
statement which she should write now to set the column 'CustiD' as the primary key of the table?
3. Kuhu has already created a table ‘Hospital’ as shown below:
3
SAI SHREE INTERNATIONAL ACADEMY, RATLAM
Now she wants to add a new column ‘Address’ to the above given table. Suggest suitable MySQL
command for the same.
4. Write SQL command to remove column named ‘Hobbies’ from a table named ‘Student’.
5. While creating the table Student last week, Ms. Sharma forgot to include the column Game_Played.
Now write a command to insert the Game_Played column with VARCHAR data type and 30 size into
the Student table?
6. Kunal created the following table with the name ‘Friends’ :
Table : Friends
Now, Kunal wants to delete the ‘Hobbies’ column. Write the MySQL statement
7. Rashi wants to add another column ‘Hobbies’ with datatype and size as VARCHAR(50) in the already
existing table ‘Student’. She has written the following statement. However it has errors. Rewrite the
correct statement.
MODIFY TABLE Student Hobbies VARCHAR;
8. Ms. Shalini has just created a table named “Employee” containing columns
Ename, Department, Salary.
After creating the table, she realized that she has forgotten to add a primary key column in the
table. Help her in writing SQL command to add a primary key column empid. Also state the
importance of Primary key in a table.
9. While creating a table 'Customer' Simrita wrongly added a primary key constraint to the field
“CUSTNAME”. Now she wants to remove the primary key constraint from the custname field. Help
her in writing the correct command.
10. Mr. Akshat have added a not null constraint to the “name” field in “employees” table. But now he
wants to remove that not null constraint. Write the command to delete the not null constraint from
name field.
Informatics Practices
My SQL Worksheet-4
(DML – UPDATE and DELETE commands)
1. What is the purpose of DROP TABLE command in SOL? How is it different from DELETE command?
2. In a database there are two tables "Product" as shown below :
Write the command To increase the Price of all the Products by 20.
4
SAI SHREE INTERNATIONAL ACADEMY, RATLAM
3. Write the UPDATE command to change “Sharma” to “Singh” in the “LastName” column in the
Employee table.
4. What is the use of UPDATE statement in SQL ? How is it different from ALTER statement?
5. Consider the following table named "GYM"
Write command To change the Brandname to "Fit Trend India" of the item, whose ICODE as "G101 ".
6. Write the UPDATE statement in MySQL to increase commission by 100.00 in the ‘‘Commission’’ column
in the ‘Emp’ table.
7. Write two examples of DML commands of SQL.
8. In a database there are two tables ‘CD’ and ‘TYPE’ as shown below :
Write SQL statement to change the name of Singer ‘‘Sonvi Kumar’’ to ‘‘Sonvi Mehra’’ in all the places
wherever it occurs in CD table.
9. Consider the following table named “GARMENT”.
1) Write command To change the colour of garment with code as 116 to “Orange”.
2) Write command to increase the price of all XL garments by 10%
3) Write command to delete the record with GCode “116”
5
SAI SHREE INTERNATIONAL ACADEMY, RATLAM
Informatics Practices
My SQL Worksheet-5
(Single Row Functions)
1. Write the output of the following SQL queries:
a) SELECT ROUND(6.5675, 2);
b) SELECT TRUNCATE(5.3456, 1);
c) SELECT DAYOFMONTH('2009-08-25');
d) SELECT MID('Class 12', 2,3);
2. Write the output of the following SQL queries :
(i) SELECT INSTR(‘UNICODE’,’CO’);
(ii) SELECT RIGHT(‘Informatics’,3);
3. State difference between date functions NOW( ) and SYSDATE( ) of MySql.
4. Name a function of MySql which is used to remove trailing and leading spaces from a string.
5. Consider the following table named 'SBOP" with details of account holders. Write output
7
SAI SHREE INTERNATIONAL ACADEMY, RATLAM