Mysql Revision Tour

7
visit @ http://www.infotechcomputer.in INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 1 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 can’t be repeated and can’t 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

description

Sumita AroraCBSE Informatics Practices

Transcript of Mysql Revision Tour

  • visit @ http://www.infotechcomputer.in

    INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 1

    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

  • visit @ http://www.infotechcomputer.in

    INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 2

    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

    structure

    It is used to delete row(s) or contents of table

  • visit @ http://www.infotechcomputer.in

    INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 3

    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

  • visit @ http://www.infotechcomputer.in

    INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 4

    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.

    >, =,

  • visit @ http://www.infotechcomputer.in

    INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 5

    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.

  • visit @ http://www.infotechcomputer.in

    INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 6

    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.

  • visit @ http://www.infotechcomputer.in

    INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 7

    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.