You are on page 1of 7

visit @ http://www.infotechcomputer.

in

Revision Tour of MySQL


Q1. Define primary key, candidate key, alternate key and foreign key?
Ans.
Primary Key : A set of one or more attributes that can uniquely identify a row in a table. It cant be
repeated and cant be NULL.
eg. admno of student table
Candidate Key : Attribute combinations in a table that can serve as a primary key are known as candidate
key.
eg. admno and roll of student table
Alternate Key : A candidate key other than primary key is called alternate key.
eg. admno of student table is primary key then rollno is alternate ey.
Q2. What is Degree, Cardinality?
Ans.
Degree : Number of columns (or) attributes (or) Fields in a table
Cardinality : Number of Rows (or) types (or) records in a table (Relation)
Q3. Difference between CHAR and VARCHAR?
Ans.
CHAR
VARCHAR
1. It specifies fixed length character string
it specifies variable lengh character string
2. it adds spaces on right of the string
it truncates spaces
Q4. Name ACID properties of transaction?
Ans. Atomicity, Consistency, Isolation, Durabillity
Q5. What is SQL? Name the classification of SQL Statements?
Ans.
SQL (Structured Query Language) is a standard language which is used to manipulate relational
database.
1. DDL (Data Defination Language) eg. create, alter, drop
2. DML (Data Manipulation Language) eg. insert, update, delete
3. TCL (Transaction Control Language ) eg. commit, rollback, savepoint
4. DCL (Data Control Language) Grant, Revoke
INFOTECH Computer Education, Kishangarh (Raj) 9829171122

Page 1

visit @ http://www.infotechcomputer.in

Q6. How would you display tables in a database?


Ans.
show tables
Q7. Which sql clause is used to restrict the rows returned by a Query?
Ans.
Distinct clause
Q8. Write MySQL command to display list of existing databases?
Ans.
show databases
Q9. Which command is used to add a new tuple in a table?
Ans.
Insert Into
Q10. Difference between WHERE clause and HAVING clause?
Ans.
Where clause is used to retrieve the records by specifying the condition for each individual row.
whereas Having clause is used to place condition on groups and aggregate functions.
Q11. A table Trains has degree 3 and cardinality 8. What is he number of rows and columns in it?
Ans.
Number of columns (degree) = 3
Number of rows (cardinality) = 8
Q12. Difference between count(*) and count(column)?
Ans.
Count(*) counts the number of characters includeing NULL and Not NULL whereas count(column) counts
the Not NULL values.
Q13. How would you view constraints, viewing columns associated in a Relation (table)?
Ans.
Using DESC (or) Describe command
Q14. Difference between DROP TABLE and DELETE?
DROP TABLE
DELETE
1. DROP TABLE is DDL Command
Delete is DML command
2. It is used to delete the contents and table
It is used to delete row(s) or contents of table
structure
INFOTECH Computer Education, Kishangarh (Raj) 9829171122

Page 2

visit @ http://www.infotechcomputer.in

Q15. What is the purpose of ORDER By Clause?


Ans.
Order By clause is used to sort the query output (i.e. in Ascending Order or Descending Order)
Q16. What are the TCL Commands ?
Ans.
Commit, Rollback and Savepoint.
Q17. How would you begin a new transaction?
Ans.
By using START TRANSACTION
Q18. Write a statemnt to set auto commit to off?
Ans.
SET AUTOCOMMIT = 0;
Q19. How would you delete a column from a table (give syntax)?
Ans. ALTER TABLE tablename DROP columnname
Q20. How would you change the data type of a column?
Ans.
ALTER TABLE tablename MODIFY column datatype(size)
Q21. Which command is used to save the changes permanently in the database?
Ans.
COMMIT
Q22. Which command is used to undo (or) cancel the previous transaction is a database?
Ans.
ROLLBACK
Q23. What is the purpose of SELECT statement ? Give its syntax ?
Ans. To display (or) to list (or) to view the information retrieved from a table (s)
SELECT column1,column2, column... from table1, table2, ... where condition order by column group by
column having condition.
Q24. Write operators used in SQL?
(i)
BETWEEN..AND to specify range as a condtion
(ii)
IN Operation To specify list of values
(iii)
LIKE To specify pattern matching condition using %, _ characters
INFOTECH Computer Education, Kishangarh (Raj) 9829171122

Page 3

visit @ http://www.infotechcomputer.in
a. % - specify any and all characters
b. _ - any single character
Q25. Neha created a table later on she realize that there is no need to include CLASS column which
command she should use to do so? [tablename is student]
Ans.
ALTER TABLE student Drop Class
Q26. A table name OFFICE has 6 rows 10 columns and another table name STAFF has 3 rows and 5
columns. How many rows and columns will be there, it we obtain the cartesian product of these two
tables?
Ans.
Number of Rows = 18 (6x3)
Number of Columns (15 (10+5)
Q27. What are six relational operations
Ans.
>, <, >=, <=, =, <> or @=
Q28. Which statement is used to create a new database?
Ans.
CREATE DATABASE
Q29. Which command in mysql is used to open a specified database?
Ans. USE databasename
Q30. Which command in mysql is used to view the structure of a table?
Ans.
DESC or DESCRIBE
Q31. What is a NULL Value?
Ans.
NULL value means that is Unavailable, Unassigned, Unknown (or) inapplicable value. Absense of value is
indicated by null value.
Q32. What is Cartesian Join?
Ans.
The join query which combines each row of one table with each row of the another table is called as
Cartesian (or) Cross Join (Or) Cartesian Product Join.

INFOTECH Computer Education, Kishangarh (Raj) 9829171122

Page 4

visit @ http://www.infotechcomputer.in
Q33. What is Equi-Join?
Ans.
The Query which combines he rows from multiple table by using equality condition on the common
columns (i.e. Primary Key of one table to Foreign key of another table) is called equi join.
Q34. Which command is used to modify existing data in a table?
Ans.
UPDATE Command
Syntax : UPDATE tablename SET columnname=value WHERE condition.
Q35. Which command is used to delete rows from a table?
Ans.
DELETE command
Syntax. DELETE FROM tablename WHERE condition
Q36. What are Constraints? Give examples?
Ans.
Constriant is a limitation or Specification or condition on a column(s).
e.g. Primary key, Not Null, Check , Foreign Key etc.
Q37. In a database there is a table Cabinet. The data entry operator is not able to insert a null value in a
column. What may the possible reason?
Ans.
The column is defined with NOT NULL or primary key constraint.
Q38. Do the Primary key of a table accept null or duplicate values?
Ans. NO. it does not accept duplicate or null values.
Q39. What is a Transaction?
Ans.
A Logical unit or work that must be done in a logical order and successfully as a grouop or not done at all
is called a transaction.
Q40. What is the purpose of inserting savepoint?
Ans.
The savepoint statement defines a marker in a transaction. It is used to rollback a transaction till the
marker.
Q41. Difference between ROLLBACK and ROLLBACK TO?
Ans. ROLLBACK is used to undo the transaction to the beginning whereas ROLLBACK TO is used to undo
the transaction upto the given savepoint name.
INFOTECH Computer Education, Kishangarh (Raj) 9829171122

Page 5

visit @ http://www.infotechcomputer.in

Q42. What is the difference between IN and BETWEEN operator?


Ans.
Between operator is used to check for numeric range comparison whereas IN operator is used for batch
comparison.
Q43. What are the types of ROLLBACK?
Ans.
Rollback can be of two types
1. Complete Rollback - it will undo the transaction to its starting point
2. Partial Rollback - it will undo the transaction to the specified savepoint.
Q44. How to check the current setting of autocommit in MySQL?
Ans.
To check the current setting of autocommit we have to issue the following command
select @@autocommit;
Q45. Create a table newstudent which contains those records of student table who got first division
marks.
Ans.
create table newstudent as(select * from student where div="First")
Q46. For what purposes ALTER TABLE command of mysql can be used?
Ans.
This Command can be used for the following purposes
1. to add a column
2. to add a integrity constraint
3. to redefine a column (datatype, size, default value)
4. to delete a column
Q47. Change the Column name First_name of student table to Firstname
Ans.
Alter Table student change First_name fname varchar(20)
Q48. What is a function in MySQL?
Ans.
A function is a special type of predefined command set that performs some operation and returns a
single value.
Q49. What are the categories of Mysql Functions?
Ans.
INFOTECH Computer Education, Kishangarh (Raj) 9829171122

Page 6

visit @ http://www.infotechcomputer.in
There are four categories of MySql Functions
1. String Functions
2. Numeric Functions
3. Date and Time Functions
4. Miscelleneous Functions
Q50 . What is a Data Dictionary ?
Ans.
A data dictionary is a file that contains "metadata" which is data about data. It helps the DBMS to find
various elements of a database while execution of a query.

INFOTECH Computer Education, Kishangarh (Raj) 9829171122

Page 7

You might also like