SQL Practice Questions
SQL Practice Questions
Q16. Answer the following questions on the basis the given table.
Admno Name Subject Sex Average
Q25. Identify the DDL and DML commands from the following.
1. Create
2. Alter
3. Insert
4. Update
5. Drop
6. Delete
7. Select
Ans
1. DDL
2. DDL
3. DML
4. DML
5. DDL
6. DML
7. DML
Q29. Which data type is used for “Date of birth” field in Student table.
Ans. Date
Q33. Data type of “name” field in a table is char(25). How many bytes
will be occupied by values “Ram” and “Rohan Kumar”?
Ans. 25
Q38. Out of char, varchar and memo, which data type is used to store
large amount of data?
Ans. memo
Q40. Write the appropriate data types for the following fields.
1. DateofBirth
2. Salary
3. Name
4. Address
5. Phonenumber
Ans.
1. Date
2. Any numeric data type preferable numeric or decimal.
3. Char or Varchar
4. Char or Varchar
5. Char or Numeric
Q53. Name the columns which are visible when we execute the
following command.
desc book;
Ans. Columns are:
Field, Type Null, Key, Default, Extra
Q54. Write the command to create the following table : “Student”
Field Name Data type Constraint
Rollno Integer (5) Primary Key
Sname Varchar(30)
Contactno Char(10) Not Null
Ans. Create table student(Rollno integer(5) not null primary key, Sname
varchar(30), Contactno char(10) not null);
Q55. Write query to insert the following record in above created table.
Roll number — 1, Name–Amit, Contact number– 1234567890
Ans. Insert into student values(1, “Amit”, “123456780”);
Q64. Write a query to add new column “Grade” of data type varchar(2)
in table ‘Student’ with default value “A”.
Ans. Alter table student add( Grade varchar(2) default “A”);
Q65. Write a query to change the data type of above added column
(Grade) to varchar(4).
Ans. Alter table student modify (Grade varchar(4));
Q70. Write a query to display all the records from table “Student”
Ans. Select * from Student;
Q84. Select count( * ) from student; return 5 and Select count(fee) from
student; return 4
why different output is coming in above two queries?
Ans. Different output shows that there must be one null value in column
fee.
Q88. Write a query to display all the records of table student whose
name starts from “A”
Ans. Select * from student where name like “A%”;
Q90. Which function return the minimum value from column fee of
table student?
Ans. min( )
Q99.Select round(12.3444,2)
Ans. 12.34
Q100. Write the query on the basis of the following table : STUDENT
Name, Admno, Subject, Average, Position
Q106. Select Name , Subject from student where average >20 and < 30;
Ans. Select Name , Subject from student where average >20
and average < 30;
Q107. Select * from Student where Name = “Amit” and Name =”Sumit”;
Ans. Select * from Student where Name = “Amit” or Name = “Sumit”;
Q110. Update table student set Name = “Sunita” where admno = 1234;
Ans. Update student set Name = “Sunita” where admno = 1234;
Write the output of the following on the basis of given
Table : Product
4. Display the detail of faculties whose name start from alphabet ‘A’.
Ans. Select * from faculty where Fname like “A%”;
5. Display details of faculties whose salary is greater than 25000 and
name ends with ‘n’.
Ans. Select * from faculty where Fsal > 25000 and Fname like “%n”;
6. Count number of faculties whose name starts with ‘S’ and salary more
than 40000.
Ans. Select count(*) from faculty where Fname like “S%” and Fsal >
40000;