You are on page 1of 16

SQL VIVA QUESTIONS

(FOR PRACTICE)
(NOTE-THE BELOW QUESTIONS AND THEIR RESPECTIVE ANSWERS HAVE BEEN SOURCED FROM
TRUSTED SITES .

 IF YOU FEEL THAT AN ANSWER MIGHT BE WRONG, KINDLY REFER TO YOUR RESPECTIVE
INCHARGE)

Q1. What is DBMS?

Ans. DBMS stands for Database Management System. It is a software which help us to
manage data effectively and efficiently.

Q2. What is the full form of RDBMS?

Ans. RDBMS stands for Relational Database Management System.

Q3. Give two example of DBMS.

Ans. Two examples of DBMS are : MySQL, Oracle, Microsoft Access etc.

Q4. What is table in DBMS?

Ans. A Table is a collection of data which is organized in the forms of rows and columns. It
is regarded as a relation in this context.

Q5. What is record in a table?

Ans. The horizontal line in a table is called record. It is also known as tuple.

Q6. What is field in a table?

Ans. The vertical line in a table is called field. It is also known as attribute.

Q7. What are the advantages of DBMS?

Ans. Advantages of DBMS are:

It reduces data redundancy.

It reduces data inconsistency.

It help in sharing of data.

Q8. Name the three types of relationship that can be formed in RDBMS.
Ans. Three types of relationship are:

One-to-One relationship

One-to-Many relationship

Many-to-Many relationship

Q9. What do you mean by Degree and Cardinality?

Ans. The number of rows in a table is called Cardinality. The number of columns i a table is
called Degree.

Q10. What is Primary Key in a table?

Ans. A field which uniquely identifies each and every record in a table is called primary key.

Q11. What do you mean by Candidate key?

Ans. Those field which can act as a primary key in a table is called candidate key.

Q12. What is alternate key in a table?

Ans. Those candidate keys which are not primary key in a table is called alternate keys.

Q13. Define Foreign Key.

Ans. A foreign key is a field or group of fields which references the primary key of another
table.

Q14. What is referential integrity in DBMS?

Ans. Referential integrity refers to the limitations which ensures the relationship between
tables. In simple words we can say that it refers to the relationship between tables.

Q15. What is MySQL?

Ans. It is an open source RDBMS.

Q16. What is SQL?

Ans. SQL stands for Structured Query Language. It is used to perform certain operations on
database.

Q17. Expand DML and DDL.

Ans. DML stands for Data Manipulation Language. DDL stands for Data Definition
Language.

Q18. Give two example of DDL commands


Ans. DDL: Create, Alter, Drop

Q19. Give two examples of DML commands.

Ans. DML : Insert, Update, Delete

Q20. Define data type.

Ans. A data type refers to the kind of data that a variable can store such as integer, floating,
string, etc.

Q21. Differentiate between Char and Varchar?

Ans.

Char Varchar

It is a fixed length data type It is a variable length data type

It uses static memory location It uses dynamic memory location

It can hold maximum of 255 characters It can hold maximum of 65535 characters

Q22. What is NULL value in MySQL?

Ans. Null Value means that data is missing or unknown.

Q23. What do you mean by comments in MySQL?

Ans. Non executable statements in MySQL are called comment.

Q24. Which symbols are used to give Single line and Multiple line comment in MySQL?

Ans. For Single line comments we use # or — symbols

For Multiple line comment we use /*——-*/

Q25. Write a command to display all the existing databases in MySQL.

Ans. Show databases;

Q26. Define constraint in MySQL.

Ans. Constraints are referred to rules or limitations that we enforced on the columns of a
table.

Q27. Name any two commonly used constraint.

Ans. Commonly used constraints are :


Not Null

Unique

Primary Key

Default

Q28. What is the difference between Unique and Primary Key constraint?

Ans. Primary key will not accept NULL values whereas Unique key can accept NULL
values. A table can have only one primary key whereas there can be multiple unique key in a
table.

Q29. Write a command to display the structure of table “Stock”

Ans. Desc Stock;

Q30. Which constraint ensures that a column can not have a NULL value?

Ans. NOT NULL

Q31. What is the difference between Update and Alter command in MySQL?

Ans. Update command is used to modify the data of the table and Alter command is used to
modify the structure of the table.

Q32. What is the difference between the following queries?

Delete from Book;

Delete from Book where price > 400;

Ans. The first query will delete all the records from table book while the second command
will delete only those records from table Book whose price is more than 400.

Q33. Write a command to make Book_id as primary key after creating the table.

Ans. Alter table Book add Primary Key (Book_id);

Q34. Which command is used to add a new column in a table?

Ans. Alter

Q35. Write a command to add a new column “Price” in a table “Book”.

Ans. Alter table Book add Price float(6,2);

Q36. What is the meaning of float(6,2)?


Ans. float(6,2) refers to a decimal number with total 6 digits including 2 decimal places.

Q37. Write a command to delete a column “Price” from table “Book”.

Ans. Alter table Book drop column Price;

Q38. Write a command to rename a column “Price” to “Amount” of table “Book”.

Ans. Alter table Book change Price Amount float(6,2);

Q39. What is the difference between Delete and Drop command?

Ans. Delete command is used to delete one or more records from the table while Drop
command is used to delete the complete data along with the structure of the table.

Q40. Write a command to delete the table “Book”.

Ans. Drop table Book;

Q41. Which command is used to remove the database?

Ans. Drop

Q42. Name the command used to fetch data from the table.

Ans. Select Command

Q43. What is the purpose of Order by Clause?

Ans. Order by Clause is used to arrange the data of the table in ascending or descending
order. This clause is used along with Select command.

Q44. What is the output of the following command?

Select 5 + NULL;

Ans. NULL

Q45. Which operator is used for pattern matching?

Ans. Like

Q46. Name two wildcard symbols which are used in MySQL for pattern matching.

Ans. Underscore ( _ ) and Percentage (%)

Q47. Which wildcard character is used for single character?

Ans. Underscore ( _ )

Q48. Correct the following query


Select * from Book where Price = NULL;

Ans. Select * from Book where Price is NULL;

Q49. By default Order by clause arrange records in _________________ order.

Ans. Ascending

Q50. Which pattern is used along with Like operator to display only those names which ends
with ‘na’?

Ans. “%na”

Q51. Which pattern is used along with Like operator to display only those names which
starts with ‘na’?

Ans. “na%”

Q52. Which pattern is used along with Like operator to display only those names which
contains ‘na’?

Ans. “%na%

Q53. Which pattern is used along with Like operator to display only those names which
contains only four characters?

Ans. “_ _ _ _ “

Q54. Which pattern is used along with Like operator to display only those names which ends
with ‘na’ and contains total 6 characters?

Ans. “_ _ _ _ na”

Q55. Which symbol is used for “Not equals to” relational operator?

Ans. <> or !=

Q56. Name the clause which is used to display unique values from a column.

Ans. Distinct

Q57. Name three logical operators in MySQL.

Ans. AND, OR, NOT

Q58. How many values return by aggregate functions in MySQL?

Ans. Single value

Q59. What do you mean by aggregate function?


Ans. Aggregate function perform calculation on a set of values and return a single value.

Q60. Give two examples of aggregate functions.

Ans. Count( ), Sum( ), Avg( )

Q61. Which aggregate function return the total number of values in a column?

Ans. Count( )

Q62. What is the difference between Count( ) and Count(*)?

Ans. Count(*) returns the total number of records in a table while Count( ) function return the
total number of values in a specific column which are not NULL.

Q63. Which aggregate function return the lowest value from a specific column?

Ans. Min( )

Q64. Which aggregate function return the largest value from a specific column?

Ans. Max( )

Q65. Which aggregate function return the addition of all the numeric values in a column?

Ans. Sum( )

Q66. Which aggregate function return the average of all the numeric values in a column?

Ans. Avg( )

Q67. Write a command to find the average of column “Price” in table “Book”

Ans. Select avg(Price) from Book;

Q68. What would be the output of the following query?

Price 3000 2500 NULL 3500

Select AVG(Price) from Book;

Ans. 3000

Q69. Differentiate between Order by and Group by clause.

Ans. Order by clause is used to arrange records in increasing or decreasing order while
Group by clause is used to combine the records of a table which have duplicate values in a
particular field.
Q70. What is function?

Ans. A function is a predefined command that perform some operations and return a single
value.

Q71. Name two types of functions available in MySQL.

Ans. Two types of functions are Single Row functions and Multiple Row functions
(Aggregate functions)

Q72. Name any two single row functions.

Ans. round(), ucase(), lcase() etc.

Q73. Name a string function which returns the character for each integer passed.

Ans. char( )

Q74. Which function concatenates two string in MySQL?

Ans. concat( )

Q75. What is the purpose of lower() function in MySQL?

Ans. This function converts a string into lower case.

Q76. Name a function which converts the string into uppercase.

Ans. Upper( ) or Ucase( )

Q77. In MySQL, which function extracts a substring from a given string?

Ans. Substr( )

Q78. Write the output of the following query:

Select substr(“CSIPLEARNINGHUB”,3,7); [/showhide]

Ans. IPLEARN

Q79. Which function removes the leading spaces from the left of the given string?

Ans. Ltrim( )

Q80. Which function removes the leading and trailing spaces from the given string?

Ans. Trim( )
Q81. Name a function which returns the length of the given string.

Ans. Length( )

Q82. Write the output of the following:

Select len(substr(“Computer Science”, 4, 8));

Ans. 8

Q83. Write the output of the following:

Select instr(“Corporate”, “or”);

Ans. 2

Q84. Name any two String functions of MySQL which return numeric value.

Ans. Length( ), Instr( )

Q85. Which function of MySQL returns the specific number of characters from the left side of
the string.

Ans. Left( )

Q86. How many arguments can be passed to substr() function in sql?

Ans. Three

Q87. Name any two numeric functions of MySQL.

Ans. Mod( ) and Power( )

Q88. Write the output of the following:

Select mod(9, 2);

Ans. 1

Q89. Write the output of the following:

Select mod(9, 12);

Ans. 9

Q90. Is Power() a mathematical function in SQL?

Ans. Yes

Q91. What is Power( ) function in SQL?


Ans. The Power( ) function returns the value of a number raised to the power of another
number.

Q92. Write the output of the following.

Select round(15.164, 1);

Ans. 15.2

Q93. Write a statement to round off value 15.164 to nearest tens.

Ans. Select round(15.164, -1)

Q94. Write a statement to find the square root of 25.

Ans. Select sqrt(25);

Q95. Write a statement to truncate value 12.67 to one decimal place.

Ans. Select truncate(12.67, 1);

Q96. Which function returns the current date?

Ans. Curdate( )

Q97. Write a query to display the current date of your system.

Ans. Select curdate( );

Q98. Name a function which extracts the month part from date expression.

Ans. Month( )

Q99. Which function returns the name of the month in MySQL?

Ans. Monthname( )

Q100. Write the output of the following.

Select Day(“2015-05-13”)

Ans. 13

Q101. What is the difference between Monthname( ) and Dayname() function in MySQL?

Ans. Monthname( ) function returns the name of the month from the date expression while
Dayname( ) function returns the name of the day from the date expression.

Q102. Differentiate between Month( ) and Day( ) function in MySQL?

Ans. Month( ) function returns the month from the date passed while Day( ) function returns
the day from the date passed.

Q103. What is the difference between Now( ) and Sysdate( )?

Ans. Now( ) function returns the begin time of statement while Sysdate( ) function returns
the begin time of its own.

Q104. What will be the output of : Select Concat(“CS”, “IP”, “IT”)

Ans. CSIPIT

Q105. What are the two types of comment styles in MySQL?

Ans. Single line comment and Multiple line comments.

Q106. What is Join in MySQL?

Ans. A way to combine records from multiple tables which have common fields.

Q107. Define Equi Join.

Ans. Equi Join creates a Join for matching column(s) values of the relative tables.

Q108. What is Natural Join?

Ans. Natural join is an operation that creates join on the basis of the common columns in
two tables.

Q109. Differentiate between Numeric and String Functions.

Ans.
Numeric Function String Function

Accept only number as argument Accept only text as argument

It returns only numeric values It returns both numeric and text values
FROM CBSE:

You might also like