0% found this document useful (0 votes)
260 views14 pages

My SQL Commands

This document provides summaries of common MySQL commands and SQL statements. It describes how to create and drop databases and tables, select data using queries with keywords like SELECT, WHERE, ORDER BY, LIKE and operators like BETWEEN, OR, and IN. It also covers inserting, updating, and deleting data. Descriptions include syntax examples to retrieve specific records by filtering columns, sorting result sets, pattern matching, and more.

Uploaded by

SHASHANK RAJPUT
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
0% found this document useful (0 votes)
260 views14 pages

My SQL Commands

This document provides summaries of common MySQL commands and SQL statements. It describes how to create and drop databases and tables, select data using queries with keywords like SELECT, WHERE, ORDER BY, LIKE and operators like BETWEEN, OR, and IN. It also covers inserting, updating, and deleting data. Descriptions include syntax examples to retrieve specific records by filtering columns, sorting result sets, pattern matching, and more.

Uploaded by

SHASHANK RAJPUT
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/ 14

MySql Commands

Create database: create database statement is used to create a new database.


syntax:
create database <database name>

Use : The USE Statement is used to select a database and perform SQL operations into that data-
base.
syntax:
use <database name>

show databases: Displays the list of databases on the MySQL server host.

show tables: To get a list of the tables in a MySQL database

drop database : Drops all tables in the database and deletes the database
syntax:
drop database <database name>

select database() : To know which database is in use currently

1. Write mysql command to create a database named “Employee”


Ans : create database Employee

2. Sharmila wants to make the database name ‘COMPANY’ active and display the names of all the
tables in it. Write MYSQL commands for it. [2015 D]
Ans:
create database COMPANY
use COMPANY
show tables

3. Which sql command is used to show the name of currently active database.
Ans : select database()

4. Write MySql ecommand to delete the database Employee


Ans drop database Employee

Create table: The CREATE TABLE statement allows you to create a new table in a database.
syntax:
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....
);
The following example creates a table called “Student” that contains five columns: Rollno, Name, Age,
Marks, and Gender.
mysql>create table student(rollno int(3),Name char(20),Age int(2),Marks int(3),Gender char(1))
Describe or Desc: DESCRIBE command is used to show the structure of table like column names and
constraints on column name. The DESC is the short form of DESCRIBE command.
The followng example show the structure of above created table ‘student’
mysql> describe student
output

5. Saumya had previously created a table named “Product” in a database using MYSQL.
Later on she forgot the table structure. Suggest to her the suitable MYSQL command through which
she can check the structure of the already created table. [SP 14]
Ans:Desc Product
or
Describe Product

INSERT INTO: The INSERT INTO statement is used to insert new records in a table. We can write
insert into statemet in two ways:

1.When insert data only in specified columns: Specify the column’s name in insert into statement
when you want to insert values in specified columns in table.
Syntax:
insert into <table name>(<columns name>) values(<values>)
for example if a student table having fields(rollno,stuname,age,marks) and the following insert into
statement can be used if you want to insert a record with rollno and age only
insert into student (rollno,age) values(5,18)
NULL value will be stored automatically in rest of the fields i.e. stuname,marks

2. When adding values in all columns: If you want to add values for all the columns of the table then
no need to specify the column names in the SQL query. But make sure the order of the values must be
in the same order as the columns in the table. The syntax would be as follows:
insert into <table name> values(value1,value2,.....)
The following insert into staement adding new record in student table for all fields
insert into student values(6,’aman’,17,89)

6. Rewrite the following SQL statement after correcting error(s). Underline the correction made.
INSERT IN EMP(EMPNO,SALES) VALUE(100,20078.50) [2015 D]
Ans: INSERT INTO EMP (EMPNO,SALES) VALUES(100,20078.50)

Select statement: The SELECT statement is used to select data from one or more tables.
Select * from student;
or
select all from student;
The above statement selects all the fields from the student table. To select specified field(s), give fields
name instead of * or all.
Select name,age from student;
The above staement displays only name and age of all students.

Where clause: The WHERE clause is used to extract only those records that fulfill a specified condi-
tion.
syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
The followng example displays the name and age of male students only
Select name,age from student where Gender=’M’:

ORDER BY:
The SQL ORDER BY clause is used to sort the data in ascending or descending order according to one
or more columns.
The following shows the syntax of the ORDER BY clause:

SELECT
select_list
FROM
table_name
ORDER BY
sort_expression [ASC | DESC];

In this syntax:
First, place the ORDER BY clause after the FROM clause.
Second, specify a sort expression(asc or desc) after the ORDER BY clause.ASC option is used to sort
the result set by the sort expression in ascending order and DESC option is used to sort the result set
by the sort expression in the descending order.
Note that the ORDER BY clause uses the ASC option by default.

Delete: The SQL DELETE statement is a used to delete one or more records from a table.
Syntax:
delete from <tablename> [where condition]
where condition is otpional and used to delete specity record(s), If no conditions are provided, all re-
cords in the table will be deleted.

Drop table : The drop table command is used to delete a table (physically) as well as all records
Syntax:
drop table <tablename>

9. Mr. William wants to remove all the rows from Inventory table to release the storage space, but he
does not want to remove the structure of the table. What MySql statement should he use?[2012 D]
Ans: delete from Inventory

10. 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? [2012 OD]
Ans : drop table Backup
LIKE : The SQL LIKE clause is used to search for a specified pattern using wildcard operators.The
LIKE condition is used in the WHERE clause of a SELECT, INSERT, UPDATE, or DELETE statement.
There are two wildcards used in conjunction with the LIKE operator
Wildcard Explanation
% Allows you to match any string of any length (including zero length)
_ Allows you to match on a single character
These symbols can be used in combination.

Note: If you are pattern matching with char datatypes, remember that chars are padded with spaces
at the end to fill the length of the field. This may give you unexpected results when you use the LIKE
condition to pattern match at the end of a string.

11. The Mname Column of a table Members is given below: [D2011]


Mname
Aakash
Hirav
Vinavak
Sheetal
Rajeev
Based on the information, find the output of the following queries:
(i) Select Mname from members where mname like “%v”;
(ii) Select Mname from members where mname like “%e%”;
Ans: (i)
Mname
Hirav
Rajeev
(ii)
Mname
Sheetal
Rajeev

12. The LastName column of a table “Directory” is given below: [2011 SP]
LastName
Batra
Sehgal
Bhatia
Sharma
Mehta
Based on this information, find the output of the following queries:
a) SELECT lastname FROM Directory WHERE lastname like “_a%”;
b)SELECT lastname FROM Directory WHERE lastname not like “%a”;
Ans : (a)
LastName
Batra
(b)
LastName
Sehgal

13. Write SQL query to display employee details from table named ‘Employee’ whose ‘firstname’ ends
with ‘n’ and firstname contains a total of 4 characters (including n). [comptt 17]
Ans :select * from employee where firstname like ‘_ _ _n’

14. Which one of the following SQL queries will display all Employee records containing the word
“Amit”, regardless of case (whether it was stored as AMIT, Amit, or amit etc.)?
(i) SELECT * from Employees WHERE EmpName like UPPER ‘%AMIT%’;
(ii) SELECT * from Employees WHERE EmpName like ‘%AMIT%’ or ‘%Amit%’ or ‘%amit%’;
(iii) SELECT * from Employees WHERE UPPER(EmpName) like ‘%AMIT%’; [D 17]
Ans (iii) SELECT * from Employees WHERE UPPER(EmpName) like ‘%AMIT%’;

NULL : Null or NULL is a special marker used to indicate that a data value does not exist in the da-
tabase. A field with a NULL value is a field with no value. The IS NULL condition is used in SQL to test
for a NULL value.

15. Pooja, a student of class XI, created a table “Book”. Price is a column of this table. To find the details
of books whose prices have not been entered she wrote the following query:
Select * from Book where Price = NULL;
Help Pooja to run the query by removing the errors from the query and rewriting it. [2011 SP]
Ans : Select * from Book where Price is NULL;

DISTINCT: The SQL DISTINCT keyword is used to eliminate all the duplicate records and fetching
only unique records.

19. Consider the table ‘Employee’ [2015 SP]


Employee
Name Location
Gurpreet Mumbai
Jatinder Chennai
Deepa Mumbai
Harsh Chennai
Simi New Delhi
Anita Bengaluru
Write the SQL command to obtain the following output:
Location
Mumbai
Chennai
New Delhi
Bengaluru
Ans Select distinct location from employee

BETWEEN : BETWEEN condition is used to retrieve values within a range in a SELECT, INSERT,
UPDATE, or DELETE statement. The values can be numbers, text, or dates. BETWEEN is a shorthand
for >= AND <=. BETWEEN is inclusive, i.e. begin and end values are included.
Syntax:
expression BETWEEN begin value AND end value
For example the following statement displays the records from students table those students have got
marks between 30 and 70(both inclusive).
Select * from student where marks between 30 and 70
or
Select * from student where marks>=30 and marks<=70

OR OPERATOR: The Logical OR operator in MySQL compares two conditions and returns TRUE if
either of the conditions is TRUE and returns FALSE when both are FALSE.

IN OPERATOR : The IN operator allows you to specify multiple values in a WHERE clause.The IN
operator is a shorthand for multiple OR conditions. The “IN” operator is written as the word ‘IN’ followed
by multiple values separated by a comma inside brackets. The “IN” operator evaluates multiple values
on a single data column. If any given value is matched with the column value , it displays that data row.
If none of the values matches, the SQL statement won’t return that data row.

20. Write the equivalent of following SQL statement using IN operator.


Select storied, sum(salesamount) from sales where storied=25 or storied=40. [comptt 16]
Ans: Select storied, sum(salesamount) from sales where storied in(25,40)

21.Write the following statement using ‘OR’ logical operator : [comptt 17]
SELECT first_name, last_name, subject FROM studentdetails WHERE subject IN (‘Maths’, ‘Sci-
ence’);
Ans: SELECT first_name, last_name, subject FROM studentdetails WHERE subject = ‘Maths’ or sub-
ject= ‘Science’

23. Mrs. Sen entered the following SQL statement to display all Salespersons of the cities “Chennai”
and ‘Mumbai’ from the table ‘Sales’. [D 16]
Table :Sales
Scode Name City
101 Aakriti Mumbai
102 Aman Punjab
103 Banit Delhi
104 Fauzia Mumba
SELECT * FROM Sales WHERE City=’Chennai’ AND City=’Mumbai’;
Rewrite the correct statement if wrong or write “statement is correct”.
Ans : SELECT * FROM Sales WHERE City=’Chennai’ or City=’Mumbai’;

PRACTICAL QUESTIONS

24. Give SQL commands to


(i) create a database team
(ii) Show the list of all databases
(iii) Open the database team
(iv) create table player with the following fields
Filed Name Data Type Sie Constraints
Pno Char 10 Primary key
Name Char 20 Not Null
Score int 3

(v) Insert the following records


PNO NAME SORE
P1 RISHABH 52
P2 HUSSAIN NULL
P3 ARNOLD 23
P4 ARNAV NULL
P5 GURSHARAN 42
(vi) Show the list of tables
(v) Show the structure of table player

25. Give SQL commands to


(i) create a database emp;
(ii) Show the list of all databases
(iii) Open the database emp
(iv) create table employee with the following fields
Filed Name Data Type Sie Constraints
Eno int 10 Primary key
Ename Char 20 Not Null
Sal int 5
(v) Insert the following records
ENO ENAME Sal
101 RAHUL 52000
102 HASSAN 25000
103 ARVIND Null
104 ANMOL 38000
105 GULSHAN Null
(vi) Show the list of tables
(v) Show the structure of table employe
(vi) Show all records whose sal between 25000 and 35000
(vii) Delete the table employee physically
(viii) Display the list of tables
(ix) Delete the database emp
(x) Display the list of databases

Practice Questions

26. Write mysql command to create a database named “company”

27 If a database “Employee” exists, which MySql command helps you to start working in that data-
base? [2011 SP]

28. Roli wants to list the name of all the tables in her database name “Gadgets”. Which command(s)
she should use to get the desired result. [SP 14]
29. Write MySql ecommand to delete the database Emp

30. Given below is a Table named ‘Company’ :


CODE FIRSTNAME GENDER
101 Advaita F
102 Feroze M
103 Samay M
104 Sasha F
Write output of SQL statement given below:
SELECT FIRSTNAME, CODE FROM Company WHERE GENDER = ‘F’ and FIRSTNAME LIKE ‘S%’
[comptt 2020]

32. Suggest the suitable command for the following purpose: [SP 18]
i.To display the list of the databases 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

33. Sarthya, a student of class XI, created a table “RESULT”. Grade is one of the column of this table.
To find the details of students whose Grades have not been entered, he wrote the following MySql
query. which did not give the desired result. [D 2011]
SELECT*FROM Result WHERE Grade = “Null”;
Help Sarthya to run the query by removing the errors from the query and write the correct Query.

35. Rewrite the following SQL statement after correcting error(s). Underline the corrections made.
INSERT IN STUDENT(RNO,MARKS) VALUE (5,78.5); [compt 2014]

37. Write SQL statement to delete rows with SCode greater than 701 in Supplier table. [comptt 2020]

38. Charvi wants to delete the records where the “FirstName” is “Rama” in the ‘Emp’ Table. She has
entered the following SQL statement. An error is being displayed. Rewrite the correct statement.
DELETE ‘Rama’ FirstName FROM Emp; [OD 16]

39. Name the SQL commands used to:


(i) Physically delete a table from the database (ii) Display the structure of a table.

40. Write MySql command will be used to open an already existing database “LIBRARY”. [D 2011]

41. Write MySql command to open an existing database. [2012 OD]

42. Write MySQl command to display the list of existing databases. [2012 D]

UPDATE(): The UPDATE command in SQL is used to modify or change the existing records in a
table. If you want to update a particular value, then you can use where condition otherwise changes
will take effect in all records.
Syntax:
UPDATE table_name SET col1=val1, col2=val2…[Where condition];
43. In the table “Student”, Priya wanted to increase the Marks (Column Name:Marks) of those
students by 5 who have got Marks below 33. She has entered the following statement: [2018]
SELECT Marks+5 FROM Student WHERE Marks<33;
Identify errors(if any) in the above statement. Rewrite the correct SQL statement.
Ans Error : UPDATE should be used instead of SELECT
Correct SQL statement:
UPDATE Student SET Marks= Marks+5 WHERE Marks<33;

44.Write the UPDATE statement in MySQL to increase commission by 100.00 in the ‘‘Commission’’
column in the ‘Emp’ table. [compt 2014]
Ans: update emp set commission = commission +100

45 Ms. Saloni wants to assign the value 700 as value in Fee Column for all the students in table named
“STUDENT”. She has entered the following SQL statement:
UPDATE STUDENT ASSIGN Fee= 700;
Rewrite the correct statement if there is any error. [comptt 2020]
Ans UPDATE STUDENT SET Fee=700;

46. The ____________command can be used to makes changes in the rows of a table in SQL.
[SP 21]
Ans update

47 Which command is used in MySQL to


(i)open the database
(ii)delete the records
(iii)insert new record
(iv)delete the table physically
(v)modify records
(vi)create a table
Ans: i. use ii.delete iii.insert into iv.drop table v update vi create table

Alter table: The MySQL ALTER TABLE statement is used to add, modify,rename or drop/delete
columns in a table. The MySQL ALTER TABLE statement is also used to rename a table.

Adding new column:We can perform a add column operation using Alter Table command
Syntax :ALTER TABLE table_nameADD column_name column_definition;
For example : Write a command to insert the Game_played column with VARCHAR data type and 30
size into the student table?
Ans : Alter table student add Game_Played varchar(30)

Drop column: SQL has ALTER TABLE DROP COLUMN command for removing columns from an
existing table.
Syntax:
ALTER TABLE table_name DROP COLUMN column_name;
For example : The following comand will remove Hobbies column from student table
Alter table student drop Hobbies
48 Structure of table Bank is given below
Table: BANK
FieldName Datatype Size Constraint
Acct_number Integer 4 Primarykey
Name Varchar 3
BirthDate Date
Balance Integer 8 NotNull
Give the answer of following
(a) Write command to add another column Fname of char type with 10 width.
Ans Alter table Bank add Fname char (10)
or
Alter table Bank add column Fname char (10)

(b) Write mysql command to delete the column BirthDate


Ans : Alter table Bank drop BirthDate
or
Alter table Bank drop column BirthDate

49. 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? [2011 SP]
Ans : Alter table

50. 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?

51. Write SQL command to remove column named ‘Hobbies’ from a table named ‘student’.

63. Which SQL command is used to add a new attribute in a table? [comptt 2020]
Ans ALTER TABLE

64. Which SQL aggregate function is used to count all records of a table ? [comptt 2020]
Ans COUNT(*)

65. Which clause is used with a SELECT command in SQL to display the records in ascending order of
an attribute? [comptt 2020]
Ans ORDER BY

66. In SQL, name the clause that is used to display the tuples in ascending order of an attribute.
Ans ORDER BY

67. In SQL, what is the use of IS NULL operator? [SP 21]


Ans To check if the column has null value / no value

68. Write any one aggregate function used in SQL. [SP 21]
Ans SUM / AVG / COUNT / MAX / MIN

69.Which of the following is a DDL command? [SP 21]


a) SELECT b) ALTER c) INSERT d) UPDAT
Ans ALTER

70. Which key word is used to sort the records of a table in descending order? 1[SP 2019-20]
Ans. DESC

71. Which clause is used to sort the records of a table? 1 [SP 2019-20]

72. Which command is used to modify the records of the table? 1 [SP 2019-20]

73. Which clause is used to remove the duplicating rows of the table? 1 [SP 2019-20]

74. In SQL, write the query to display the list of tables stored in a database. 1[SP 21]

75.Which of the following types of table constraints will prevent the entry of duplicate rows? 1[SP 21]
a) Unique b) Distinct c) Primary Key d) NULL

77. Write the UPDATE command to increase the commission (column name: COMM) by 500 of all the
salesmen who have achieved sales(Column name: SALES) more than 200000. The table’s name is
COMPANY. [2015 OD]

78. In ‘Marks’ column of ‘Student’ table, for Rollnumber 2, the class Teacher entered the marks as 45.
However there was a totaling error and the student has got her marks increased by 5. Write MySQL
command to change the marks in ‘Student’ table. [2015 SP]

79. Consider table ‘Book’. Write SQL statement to change the price for the BOOK titled ‘Informatics
made fun’ to 200? [comptt 16]
Bcode Title Price
101 ABC of Physics 300
102 Informatics made fun 250
103 Computers are simple 375
80. Ms. Shalini has just created a table named “Employee” containing columns Empid, Ename, Depart-
ment, 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 im-
portance of Primary key in a table. [SP 18]

81. Kuhu has already created a table ‘Hospital’ . [SP 14]


Now she wants to add a new column ‘Address’ in the hospital table. Suggest to her suitable MySQL
commands for the same.

82. Rashi wants to add another column ‘Hobbies’ with datatype and size as VARCHAR(50) in the al-
ready existing table ‘Student’. She has written the following statement. However it has errors. Rewrite
the correct statement.
MODIFY TABLE Student Hobbies VARCHAR; [comptt 17]

83.Ariya wants to add another column ‘Gender’ in the already existing table ‘CUSTOMERS’. She has
written the following statement. However , it has errors . Rewrite the correct statement.
MODIFY TABLE CUSTOMERS GENDER char(1); [OD 17] 1

84. Kunal created the following table with the name ‘Friends’: [D 16]
FriendCode Name Hobbies
F101 Bijoy Swimming
F102 Abhinav Reading books
F103 Jyotsna Dancing
Now, Kunal wants to delete the ‘Hobbies’ column. Write the MySQLstatement

87,Which command is used in MySQL to 5


(i)restrict duplicate values (ii)modify any column (iii)insert new record
(iv)insert new column (v)modify records

93.Which one of the following would arrange the rows in ascending order in SQL ? [comptt 21]
(A) SORT BY (B) ALIGN BY (C) GROUP BY (D) ORDER BY

Multiple Choice Questions


1 How to open an already existing database “EMP”
(a) open EMP (b) create database EMP (c) use EMP (d) open database EMP

2 Write MySQl command to display the list of existing databases.


(a) Select databases (b) List databases (c) Display databases (d) Show databases

3 Write command to make the database “COMP”


(a) Make database COMP (b)Create database COMP (c) Create COMP (d) use COMP

4 Write MYSQL command through you can check the structure of the already created table “PROD-
UCT”.
(a) Desc Product (b) Select Product (c) Show Product (d) Dispaly Product

5 Write command to display the names of all the tables in current database.
(a) display tables (b) show tables (c) desc tables (d) select tables

6.Write SQL command to remove column named ‘Hobbies’ from a table named ‘student’,
(i) alter table student delete Hobbies (ii) delete hobbies from student
(iii) alter table student drop Hobbies (iv) alter table student drop column Hobbies
Select the correct option
(a) i and ii are correct (b) only i is correct (c) iii and iv are correct (d) i and iii are correct

7 write a command to insert the Game_played column with VARCHAR data type and 30 size into the
student table
(i) Alter table student add Game_Played varchar(30)
(ii) Alter table student add column Game_Played varchar(30)
(iii) Update student add column Game_Played varchar(30)
(iv) Create table student add column Game_Played varchar(30)
Which option is correct
(a) i and ii are correct (b) only i is correct (c) only iii is correct (d) iii and iv are correct

8.Write MySQL command to remove all the rows from Inventory table to release the storage space, but
not to remove the structure of the table.
(a) delete * from Inventory (b)delete from Inventory (c) drop table inventory (d) drop rows inventory
9. Write MySQL statement to remove the entire content of a table “Backup” alongwith its structure to
release the storage space.
(a) delete * from Backup (b)delete from Backup (c) drop table Backup (d) Alter table drop Backup

10. Charvi wants to insert“Sharma” in the “LastName” column of the “Emp” table. Write the SQL state-
ment.
Fields of Emp(Firstname,Lastname)
(a)insert into emp(Lastname) values (‘Sharma’) ; (b)Insert into emp values(‘Sharma’)
(c) update emp set Lastname=’Sharma’ (d) insert into emp(‘Sharma’) values(Lastname)

11. Write SQL statement to change the price for the BOOK titled ‘Informatics’ to 200 in book table?
(a) update book set price=price+200 where title=’Informatics”
(b) insert into book(‘Informatics’) values (200)
(c)update book set price=200 where title=”Informatics”
(d)update book add price=200 where title=”Informatics”

12. Write Mysql command to display all information of students in descending order of name from stud
table
(a)Select name from stud order by desc (b) select name from sud desc order by name
(c) select * from stud order by desc (d) select * from stud order by name desc

13. Write MySQL command to select tuples with some salary from emp table
(a) select * from emp where salary=something (b) select * from emp where salary !=NULL
(c) select * from emp where salary is not NULL (d) select * from emp where salary # NULL

14.Write command to display maximum salary department wise from employee table
employee table(Code, Name, Salary, Deptcode)
(a)select deptcode,Max(salary) from employee group by deptcode
(b) Select deptcode, max(salary) from employee order by deptcode
(c) Select deptcode from employee where salary=max(salary)
(d) Select max(salary) from emplyee deptcodewise

15. Suggest the suitable command to remove the pre-existing database named Clients.
(a) delete database Clients (b) drop Clients (c) drop database Clients (d) Alter table drop Clients

16. Write SQL query to display employee details from table named ‘Employee’ whose ‘firstname’ ends
with ‘n’ and firstname contains a total of 4 characters (including n)
(a)select * from employee where firstname like ‘%n’
(b)select * from employee where len(firstname)=4 and like ‘%n’
(c)select * from employee where right(firstname)=’n’ and len(firstname)=4
(d) select * from employee where firstname like ‘_ _ _n’

17. Write a query to display garment names and codes of those garments that have price in the range
1000.00 and 1500.0 (Both 1000.00 and 1500.00 included) in garment table
(a) select gname,code from garment where 1000 <= price <= 1500
(b) select gname,code from garment where price 1000 to 1500
(c) select gname,code from garment where price between 1000 to 1500
(d) select gname,code from garment where price between 1000 and 1500

18. Write a query to show the information of students those name is either Khan, Yadav or Mishra.
(a)select * from student where name=”Khan”,”Yadav”,”Mishra”
(b)select * from student where name in(“Khan”,”Yadav”,”Mishra”)
(c)select * from student where name=”Khan” or “Yadav” or ‘Mishra”
(d) select * from student where name=”Khan” and “Yadav”and “Mishra”

19. Write mysql query to add another column ‘Hobbies’ with datatype and size as VARCHAR(50) in the
already existing table ‘Student
(i)Alter table student add Hobbies varchar(50)
(ii)modify table Student Hobbies VARCHAR
(iii)alter table student add column Hobbies varchar(50)
(iv)create table student ( hobbies varchar(50))
(a) Only i (b) i and iii both (c) only iii (d) iii and iv both

20. Which command is used in MySQL to modify records


(a) alter table (b) modify records (c) update (d) insert into

21. Write command to delete the database “school”


(a)drop school (b)delete database school (c)alter table drop school (d)drop database school

22. Write a query to count the number of students whose fees is less than 11000
(a) select count(no of students) from student where fees<11000
(b) select count from student where fees<11000
(c)select count(*) from student where fees<11000
(d) select no of student from student where fees<11000

23. .Delete all records those marks are between 30 and 50 from stud table
(a)delete * from stud where marks between 30 and 50
(b)delete all from stud where marks between 30 and 50
(c)delete from stud where marks between 30 and 50
(d)delete * from stud where marks between 30 to 50

24. Write command in MySQL to increase commission by 100.00 in the ‘‘Comm’’ column in the ‘Emp’
table.
(a)alter table emp add comm=comm+100 (b)update table emp set comm=comm+100
(c)update table emp set comm=100 (d)insert into emp(comm) values(100)

25. Write mysql query to list the information whose income is null from family table(Name,age,income)
(a)select information from family where income is null (b)select * from family where income=null
(c)select * from family where income is null (d)select information from family where income
= null

26. Write command to show all information whose name end with “a”(table-student)
(a)select * from student where name end “a” (b)select * from student where name like “a%”
(c)select * from student where name like “%a” (d)select * from student where name like “%a%”

Answers:
1.c 2.d 3.b 4.a 5.b 6.c 7.a 8.b 9.c 10.a 11.c 12.d 13.c 14.a 15.c 16.d 17.d 18.b 19.b 20.c 21.d 22.c 23.c
24.b 25.c 26.c

You might also like