100% found this document useful (1 vote)
377 views

MYSQL_Question Bank with solutions

Contains MySQL Worksheets for Class XI and XII CBSE

Uploaded by

SUTAPA RAHA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
377 views

MYSQL_Question Bank with solutions

Contains MySQL Worksheets for Class XI and XII CBSE

Uploaded by

SUTAPA RAHA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

MySQL Worksheet-1

1. If a database "Employee" exists, which MySQL command helps you to start working in
that database?
Use Employee;

2. Write MySQL command will be used to open an already existing database "LIBRARY".
Use Library;

3. Write MySQL command to open an existing database.


Use databasename;

4. What does SQL stand for? What is MySQL?


SQL Stands for structured query language.
Mysql is an open source RDBMS (Relational Database Management System)

5. Write two examples of DBMS software.


SQL Server, My SQL, Oracle, Ingres, Postgres

6. Sharmila wants to make the database named ‘COMPANY’ active. Write MySQL
commands for it.
Use Company;

7. What is MySQL ?
Mysql is an open source RDBMS (Relational Database Management System)

8. What is the relationship between SQL and MySQL ?


SQL is a language to give commands in MySQL or any other RDBMS software.

9. Mention any two example of common Database Management System.


SQL Server, Ingres, Postgres, MySQL

10 Suggest Anita 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.
i. Show Databases;
ii. Use City;
iii. Drop database clients;

11 Write the command to display the name of the active database.


.
Select Database();

12 Write the command to create a new database “School”


.
Create database school;

1
MySQL Worksheet- 2
1. Write an SQL query to create the table 'Menu' with the following structure:

Create table Menu(


ItemCode varchar(5) Primary key,
Itemname varchar(20),
Category Varchar(20),
Price Decimal(5,2));
2. Can a table have multiple primary keys? Can it have multiple foreign keys?
No, a table cannot have multiple primary keys. There can only be one primary
key.
Yes, a table can a multiple foreign keys.

3. In a Student table, out of Roll Number, Name, Address which column can be set as Primary
key and why?
RollNumber can be set as Primary Key as two students cannot have a same roll
number.

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 ?
Drop Table Backup;

5. Write MySQL command to create the Table STOCK including its Constraints.
Table STOCK :

Create table Stock(


Id Decimal(4) Primary Key,
Name Varchar(20),
Company Varchar(20),
Price Decimal(8) Not Null);
6. Write one similarity and one difference between CHAR and VARCHAR data types.
Similarity:
Both char and varchar can store alphabets as well as numbers. Both can store
same type of values.
Difference:
Char is a fiied length character datatype whereas varchar is a variable length
character datatype.

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.
Describe Product;

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.

2
Use Gadgets;
Show tables;
9. Name the SQL commands used to :
(i) Physically delete a table from the database.
(ii) Display the structure of a table.
i) Drop table tablenae;
ii) Describe tablename;
10 Write one similarity and one difference between UNIQUE and PRIMARY KEY constraints.
.
Similarity:
Both Unique and primary key restricts duplicate values in the field.
Difference:
Unique allows null values whereas Primary doesnot allow null values to be
inserted in the field.
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?
A will occupy 4 character space.
B will occupy 20 character space.
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.
i) RollNo and Name can be the attributes of student table.
ii) RollNo can become the primary key of the student table as two students
cannot have a same roll number.
13 Write SQL query to create a table ‘Player’ with the following structure:
.

Create table Player(


Playerid integer primary key,
Name varchar(50),
Height integer,
Weight integer,
Datebirth date,
Teamname varchar(50));
14 Anita has created the following table with the name ‘Order’.
.

One of the rows inserted is as follows :

3
(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 :

Will she be able to successfully insert it ? Give reason.


i) The datatype for orderID field can be either char or varchar
The datatype for orderDate is date
ii) She will not be able to insert the above record as she is inserting a null
value in the orderdate field and the orderdate field have a not null
constraint which cannot accept null values.
15 Write SQL query to create a table ‘Event’ with the following structure :
. Field Type Constraint
EventId Varchar(5) PRIMARY KEY
EventName Varchar(30) NOT NULL
Location Varchar(50)
ClientID Integer
EventDate Date
Create table Event(
EventID varchar(5) Primary Key,
EventName varchar(30) not null,
Location varchar(50),
CleintID Integer,
EventDate date);
16 Observe the given table carefully and answer the following questions:
.

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.
i. PanNo might have a Primary Key constraint as two person cannot have
a same Pan Number.
ii. PhoneNo might have a unique constraint as two person will be having
different mobile numbers.
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 :

4
Create table Event(
EventID Integer Primary Key,
Event Varchar(50),
DateEvent Date,
NumPerformers Integer);
18 suggest her 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.
iv. To remove all the records of the table named “Club” at one go along with its
structure permanently.
i. Show databases;
ii. Use City;
iii. Drop database Clients;
iv. Drop table Club;
19 While creating a table named “Employee”, Mr. Ramesh got confused as which data type he
. should chose for the column “EName” out of char and varchar. Help him in choosing the
right data type to store employee name. Give valid justification for the same.
EName field can have a varchar as a datatype as two employees will not be
having a same length of their names.

MySQL Worksheet-3

1. Kunal 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?
Alter table tablename add fieldname datatype(size);

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?
Alter table customer add primary key(custid);

3. Kunal has already created a table ‘Hospital’ as shown below:

Now she wants to add a new column ‘Address’ to the above given table. Suggest suitable
MySQL command for the same.
Alter table hospital add address varchar(30);

4. Write SQL command to remove column named ‘Hobbies’ from a table named ‘Student’.
Alter table student drop hobbies;

5
5. While creating the table Student last week, Ms. Roy 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?
Alter table student add game_played varchar(30);

6. Kunal created the following table with the name ‘Friends’ :


Table : Friends

F101 Bijoy Swimming


Now,F102
Kunal wants Abhinav
to delete theReading
‘Hobbies’ column. Write the MySQL statement
books
F103 Jyotsna Dancing
Alter table friends drop hobbies;

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;
Alter table student add hobbies varchar(50);
8. Ms. Sharma 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.
Alter table employee add primary key(empid);

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.
Alter table customer ass primary key(custname);

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.
Alter table employee modify name varchar(30) null;

6
MySQL Worksheet-4
1. Madhu is not able to change a value in a column to NULL. What constraint did she specify
when she created the table?
Not Null, Primary Key

2. Consider the table RESULT given below.

Write command to insert a new row


6, "Mohan", 500, "English", 73, "Second"
Insert into Result values(6, "Mohan", 500, "English", 73, "Second");

3. Consider the Table SHOPPE given below.

To insert a new row in the table Shoppe


'108', 'Pizza' , Dominos, 109, "Kolkata", 89.0
Insert into Result values('110', 'Pizza' , 'Papa Jones', 120, "Kolkata", 50.0);

4. How is NULL value different from 0 (Zero) value?


Null means no value whereas 0 is a value.

5. Consider the following table named "GYM"

Add a new row for a new item in GYM with the details: "G107", "Vibro exerciser” ,21000,
“GTCFitness"
Insert into Result values("G107", "Vibro eierciser” ,21000, “GTCFitness");

6. What is meant by NULL value in MySQL?


Null means no value

7. Rewrite the following SQL statement after correcting error(s). Underline the corrections
made.
INSERT IN STUDENT(RNO,MARKS) VALUE (5,78.5);
INSERT INTO STUDENT(RNO,MARKS) VALUES (5,78.5);

8. Rewrite the following SQL statement after correcting error(s). Underline the corrections
made.
INSERT IN EMP(EMPNO, SALES) VALUE (100, 20078.50);
INSERT INTO EMP(EMPNO, SALES) VALUES(100, 20078.50);

9. Arushi is inserting “Sharma” in the “LastName” column of the “Emp” table but an error is
being displayed. Write the correct SQL statement.
INSERT INTO Emp(‘Sharma’)VALUES(LastName) ;
INSERT INTO Emp(LastName) VALUES(‘Sharma’) ;

10 Amita has created the following table with the name ‘Order’.
.

7
One of the rows inserted is as follows :

(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 :

Will she be able to successfully insert it ? Give reason.


i) The datatype for orderID field can be either char or varchar
The datatype for orderDate is date
ii) She will not be able to insert the above record as she is inserting a null value
in the orderdate field and the orderdate field have a not null constraint
which cannot accept null values.

11 In today’s digitized world with a need to store data electronically, it is very important to
. store the data in the databases. SQL is used to interact with the Database Management
System.
Classify the following commands according to their type :(DDL/DML)
i. INSERT INTO ii. ALTER TABLE
i. DML ii. DDL

12 Is NULL and 0(zero) same? Jusify your answer.


.
No null is not same as 0. Null means no value. 0 is a value.
Any numerical calculation on null will give null
Any numerical calculation on 0 will do the actual calculation.

8
9

You might also like