MYSQL_interview_questions

Why a database is called as relational database model?

A database model represents the relationship between one or more databases. The relationship is known as the relational database model. It is an extension of the normal databases without relations. It provides flexibility and allows one database to be in relation with another database. It can access the data from many databases at one time over the network.

What are entities and attributes referring to?

What do you understand by relation in relational database model?

Relation in the relational database model is defined as the set of tuples that have the same attributes. Tuple represents an object and also the information that the object contains. Objects are basically instances of classes and used to hold the larger picture. Relation is described as a table and is organized in rows and columns. The data referenced by the relation come in the same domain and have the same constraints as well. Relations in the relational database model can be modified using the commands like insert, delete etc.

Why domain is of high importance?

For example: XYZ doesn’t fulfill the domain constraint but the integer value as 899 fulfills the criteria of domain constraint. Hence, domain is of high importance.

What is the difference between base and derived relation?

What are constraints in database?

Constraints are kind of restrictions that are applied to the database or on the domain of an attribute. For example an integer attribute is restricted from 1-10 and not more than that. They provide the way to implement the business logic and the rules in database. In database it can be implemented in the form of check constraints that checks for the rules that haven’t been followed by the programmer. Constraint also used to restrict the data that can be stored in the relations. Domain constraint can be applied to check the domain functionality and keep it safe..

What are the two principles of relational database model? What is the difference between them?

The two principal rules for the relational model are as follows:

The differences between them are as follows:

What is the difference between primary and foreign key?

Why stored procedures are called as executable code?

Stored procedure stored inside the database. This also includes the executable code that usually collects and customizes the operations like insert, encapsulation, etc. These stored procedures are used as APIs for simplicity and security purposes. The implementation of it allows the developers to have procedural extensions to the standard SQL syntax. Stored procedure doesn’t come as a part of relational database model, but can be included in many implementations commercially.

What is an index represent in relational database model?

What are the relational operations that can be performed on the database?

There are many relational operators that are used to perform actions on relational database. These operators are as follows:

  1. Union operator that combines the rows of two relations and doesn’t include any duplicate. It also removes the duplicates from the result.
  2. Intersection operator provides a set of rows that two relations have in common.
  3. Difference operator provide the output by taking two relations and producing the difference of rows from first that don’t exist in second.
  4. Cartesian product is done on two relations. It acts as a cross join operator.

What do you understand by database Normalization?

What are the different types of normalization that exists in the database?

There are 9 normalizations that are used inside the database. These are as follows:

  1. First normal form: in this table represents a relation that has no repeating groups.
  2. Second normal form: non- prime attributes are not functional dependent on subset of any candidate key.
  3. Third normal form: in a table every non- prime attribute is non-transitively dependent on every candidate key
  4. Elementary key normal form: superkey dependency or elementary key dependency effects the functional dependency in a table.
  5. Boyce codd normal form: “every non-trivial functional dependency in the table is dependent on superkey”.
  6. Fourth normal form: “Every non-trivial multivalued dependency in the table is a dependent on a superkey”.
  7. Fifth normal form (5NF): “Every non-trivial join dependency in the table is implied by the superkeys of the table”.
  8. Domain/key normal form (DKNF): “Every constraint on the table is a logical consequence of the table’s domain constraints and key constraints”.
  9. Sixth normal form (6NF): “Table features no non-trivial join dependencies at all”.

How de-normalization is different from normalization?

What is the type of de-normalization?

Non-first normal form (NFA)

– It describes the definition of the database design which is different from the first normal form.

How many levels of data abstraction are available?

There are three levels of data abstraction available in database model and these are as follows:

  1. Physical level: It is the lowest level that describes how data is stored inside the database.
  2. Logical level: It is the next higher level in the hierarchy that provides the abstraction. It describes what data are stored and the relationship between them.
  3. View level: It is the highest level in hierarchy that describes part of the entire database. It allows user to view the database and do the query.

What is the difference between extension and intension?

The major difference between extension and intension is that:

What are its two major subsystems of System R?

System R is being developed by IBM. Its purpose is to demonstrate the possible solution to build a relational database system. The relational database system has to be such that which can interact with the real life environment to sole real life scenarios.

The two subsystems that are included in it are:

  1. Research storage: This includes the research information of the database.
  2. System relational system: This includes the relational data that a system has to produce and keep everything in relation.

What do you understand by Data Independence?

Data independence tells about the independence of the data inside the application. It usually deals with the storage structure and represents the ability to modify the schema definition. It doesn’t affect the schema definition which is being written on the higher level.

There are two types of data independence:

  1. Physical data independence: It allows the modification to be done in physical level and doesn’t affect the logical level.
  2. Logical data independence: It allow the modification to be done at logical level and affects the view level.

NOTE: Logical Data Independence is more difficult to achieve.

Why E-R models are used?

E-R model stands for entity-relationship model and it is used to represent a model with their relationships. This is an object oriented approach and it is based on real world that consists of objects which are called entities and relationship between them. Entities are further used inside the database in the form of attributes.

What is the purpose of acid properties?

What do you understand by cardinality and why it is used?

What is the difference between DBMS and RDBMS?


What is Index?

What is Trigger?

What is a NOLOCK?

What is the STUFF function and how does it differ from the REPLACE function?

where stringToChange is the string which will have the characters those we want to overwrite, startIndex is the starting position, length is the number of characters in the string that are to be overwrited, and new_characters are the new characters to write into the string.

What are Self Join and Cross Join?

What are the advantages of using Stored Procedures?

What is RANK function?

For Example: SELECT RANK() OVER(ORDER BY BirthDate DESC) AS [RowNumber], FirstName, BirthDate FROM EmpDetails

What are cursors and when they are useful?

There are two of cursors:

  1. Implicate Cursor
    • SQL Server automatically manages cursors for all data manipulation statements. These cursors are called implicit cursors.
  2. Explicit Cursor
    • When the programmer wants to perform the row by row operations for the result set containing more than one row, then he explicitly declare a cursor with a name.
    • They are managed by OPEN, FETCH and CLOSE.
    • %FOUND, %NOFOUND, %ROWCOUNT and %ISOPEN attributes are used in both types of cursors.

What is Similarity and Difference between Truncate and Delete in SQL?

  1. TRUNCATE is a DDL (data definition language) command whereas DELETE is a DML (data manipulation language) command.

  2. We can’t execute a trigger with TRUNCATE whereas with DELETE command, a trigger can be executed.

  3. We can use any condition in WHERE clause using DELETE but it is not possible with TRUNCATE.

  4. If table is referenced by any foreign key constraints then TRUNCATE cannot work.

  5. TRUNCATE is faster than DELETE, because when you use DELETE to delete the data, at that time it store the whole data in rollback space from where you can get the data back after deletion, whereas TRUNCATE will not store data in rollback space and will directly delete it. You can’t get the deleted data back when you use TRUNCATE.

What are COMMIT and ROLLBACK in SQL?

-ROLLBACK statement is used to end the current transaction and undone the changes which was made by that transaction.

What is a WITH(NOLOCK)?

Differentiate UNION, MINUS, UNION ALL and INTERSECT?

What is a join? Explain the different types of joins?

Using Join in a query, we can retrieve referenced columns or rows from multiple tables.

Following are different types of Joins:

  1. JOIN: Return details from tables if there is at least one matching row in both tables.
  2. LEFT JOIN: It will return all rows from the left table, even if there are no matching row in the right table.
  3. RIGHT JOIN: It will return all rows from the right table, even if there is no matching row in the left table.
  4. FULL JOIN: It will return rows when there is a match in either of tables.

What is DDL, DML and DCL?

SQL commands can be divided in three large subgroups.

1) DDL: The SQL commands which deals with database schemas and information of how the data will be generated in database are classified as Data Definition Language. -For example: CREATE TABLE or ALTER TABLE belongs to DDL.

2) DML: The SQL commands which deals with data manipulation are classified as Data Manipulation Language. For example: SELECT, INSERT, etc.

3) DCL: The SQL commands which deal with rights and permission over the database are classified as DCL. For example: GRANT, REVOKE

What is Index tuning?

What is Index tuning?

Index tuning is part of database tuning for selecting and creating indexes. The index tuning goal is to reduce the query processing time. Potential use of indexes in dynamic environments with several ad-hoc queries in advance is a difficult task. Index tuning involves the queries based on indexes and the indexes are created automatically on-the-fly. No explicit actions are needed by the database users for index tuning.

How is index tuning used to improve query performance?

The Index tuning wizard can be used to improve the performance of queries and databases. It uses the following measures to do so:

How is index tuning used to improve query performance?

Reasons of poor performance of query.

Following are the reasons for the poor performance of a query:



SQL stands for

a) Structured Query Language b) Simple Query Language c) Standard Query Language d) Secondary Query Language

ANSWER: a) Structured Query Language

SQL was designed with the purpose of managing data held in__

a) Relational Database Management System b) Object Oriented Database Management System c) Object Relational Database Management System d) File system

ANSWER: a) Relational Database Management System

Which is the correct syntax to retrieve all rows from the table?

a) select * from table_name; b) select from table_name; c) select column_name from table_name; d) select column_name , from table_name;

ANSWER: a) select * from table_name;

What is the difference between delete and truncate command of SQL?

a) DROP command removes a table from the database & TRUNCATE removes all rows from a table b) TRUNCATE TABLE cannot activate a trigger because the operation does not log individual row deletions.& Delete activates a trigger because the operation are logged individually c) TRUNCATE TABLE always locks the table and page but not each row & DELETE statement is executed using a row lock, each row in the table is locked for deletion d) All of the above

ANSWER: d) All of the above

Restrictions on Dropping Tablespace

a) You cannot drop the SYSTEM tablespace. b) You cannot drop a tablespace that contains a domain index or any objects created by a domain index. c) You cannot drop an undo tablespace if it is being used by any instance or if it contains any undo data needed to roll back uncommitted transactions. d) All of the above

ANSWER: d) All of the above

If you want to add new data in a database which command will you use

a) Insert b) Add c) Update d) Select

ANSWER: a) Insert

Suppose your assistant, named Jene has not been previously authorized to add data about new customers into the database, which of the following statement can be used to give her that permission

a) Grant Insert b) Grant Update c) Revoke Insert d) Revoke All

ANSWER: a) Grant Insert

SQL select statement is used to

a) Retrieve data from database b) Update data in database c) Delete data from database d) Modify data in database

ANSWER: a) Retrieve data from database

To control access to the database which SQL statement/s used

a) Grant b) Revoke c) Both a & b d) Deny

ANSWER: c) Both a & b

Select the non-aggregate function from the following

a) Avg( ) b) Min( ) c) Max( ) d) Round( )\

ANSWER: d) Round( )

Select the non-scalar function from the following

a) UCASE() b) LCASE() c) FORMAT() d) FIRST()

ANSWER: d) FIRST()

If the primary key is not included in the query result , duplicate rows can occur in result set then how you can eliminate the duplicate rows of query result.

a) By using Distinct statement b) By using Unique statement c) Neither a nor b d) By using where clause

ANSWER: a) By using Distinct statement

What is true about FLOOR(n) function?

A) Returns smallest integer greater than or equal to n B) Returns largest integer less than or equal to n C) It is used with numeric data D) It operates on character data

a) Only A b) Only B c) A , C & D d) B & C

ANSWER: d) B & C

Pseudo-column ____ returns a level of row in a tree-structured query.

a) ROWID b) LEVEL c) ROWNUM d) ROWSCN

ANSWER: b) LEVEL

Pseudo-column LEVEL can be used in __statement where ____ is used.

a) Select, group by b) Select , connect by c) Update, order by d) Select , group by

ANSWER: b) Select , connect by

__ column displays the location of row in a database.

a) ROWID b) ROWNUM c) ROWSCN d) UID

ANSWER: a) ROWID

To use the result of certain query repeatedly which clause will you use?

a) Where b) With c) Having d) None of the above

ANSWER: b) With

Which command will you use to delete entire table from database?

a) Delete b) Drop c) Truncate d) None of the above

ANSWER: b) Drop

SQL ____performs a JOIN against equality or matching column(s) values of the associated tables.

a) Equi join b) Inner Join c) Self-Join d) Cross Join

ANSWER: a) Equi join

Exists clause is used for

a) Testing whether a given set is empty or not b) Testing whether given set is valid c) Testing whether a given set is invalid d) Testing whether a given set is exists

ANSWER: a) Testing whether a given set is empty or not.

Which of the following queries will correctly show the tables owned by the user?

a) SELECT table_name from system_user_tables; b) SELECT table_name from user_objects; c) SELECT table_name from user_catalog; d) SELECT table_name from user_tables;

ANSWER: d) SELECT table_name from user_tables;

Data files are logically grouped together into an oracle logical structure called a

a) Tablespace b) Table c) Database d) Indexes

ANSWER: a) Tablespace

To create a table name Customer having fields Cust-name, Cust_address from the table Employee and Customer table should not be populated with any record from Employee table which of the following query will be correct?

a) Create table Customer (Cust-name, Cust_address) As Select emp_name, emp_address from Employee; b) Create table Customer (Cust-name, Cust_address) As Select emp_name, emp_address from Employee 1=1; c) Create table Customer (Cust-name, Cust_address) As Select emp_name, emp_address from Employee where 1=2; d) Create table Customer (Cust-name, Cust_address) As Select emp_name, emp_address from Employee where a=b;

ANSWER: c) Create table Customer (Cust-name, Cust_address) As Select emp_name, emp_address from Employee where 1=2;

Which of the following tasks cannot be performed when using Alter Table clause?

A) Change the name of the table B) Change the name of the column C) Decrease the size of a column if table data exists

a) A & B b) A,B, & C c) Only C d) B & C

ANSWER: b) A,B, & C

The ___ command is used to change or modify data values in a table

a) Update b) Modify c) Rename d) Describe

ANSWER: a) Update

Up to how many columns can be combined to form a composite primary key for a table?

a) 16 b) 8 c) 18 d) 14

ANSWER: a) 16

Select from the following option which not true about primary key

a) Primary key can be Long & long Raw data type b) Unique index is created automatically if there is a Primary Key c) Primary key will not allow Null values d) Primary key will not allow duplicate values

ANSWER: a) Primary key can be Long & long Raw data type

####To compare one value with more than one or list of values then which of the following operator will fulfil the need?

a) Like b) IN c) AND d) Between

ANSWER: b) IN

Which of the following query is correctly give the user name of the currently logged in user?

a) SELECT USERENV FROM DUAL; b) SELECT COALESCE FROM DUAL; c) SELECT USER FROM DUAL; d) SELECT USERENV FROM TABLE_NAME;

ANSWER: c) SELECT USER FROM DUAL;

The _ operator is used to calculate aggregates and super aggregates for expressions within a ____.

a) ROLLUP, GROUP BY b) ROLLUP, ORDER BY c) CUBE , GROUP BY d) ROLLUP,CUBE

ANSWER: a) ROLLUP, GROUP BY

____ allows grantee to in turn grant object privileges to other users.

a) With grant option b) Grant c) Revoke d) Grant All

ANSWER: a) With grant option

Grant all on Customer to Reeta with grant option, what is the significance of ‘with grant option’ in this query?

a) Give the user “Reeta” privileges to view only data on table Customer along with an option to further grant permissions on the Customer table to other users. b) Give the user “Reeta” all data manipulation privileges on table Customer. c) Give the user “Reeta” all data manipulation privileges on table Customer along with an option to further grant permissions on the Customer table to other users. d) Give the user “Reeta” all data manipulation privileges on table Customer along with an option to not further grant permissions on the Customer table to other users.

ANSWER: c) Give the user “Reeta” all data manipulation privileges on table Customer along with an option to further grant permissions on the Customer table to other users.

A View is mapped to ____ statement.

a) Update b) Alter c) Create d) Select

ANSWER: d) Select

What are the prerequisite for a View to be updateable?

a) Views defined from a single table. If user wants to Insert records with the help of a view, then the primary key column and all the Not Null columns must be included in the view b) The user can Update, Delete records with the help of a view even if the primary key column and Not Null column(s) are executed from the view definition c) Both a & b d) None of the above

ANSWER: c) Both a & b

Which of the following query will correctly create the view of Employee table having fields fname,lname,dept?

a) Create View emp_v In select fname,lname,dept from Employee; b) Create View emp_v As select fname,lname,dept from Employee; c) Create View emp_v like select fname,lname,dept from Employee; d) Create View emp_v As select , , fname,lname,dept , ,from Employee;

ANSWER: b) Create View emp_v As select fname,lname,dept from Employee;

Which of the following column is not a part of USER_CONSTRAINTS?

a) OWNER b) TABLE_NAME c) SEARCH_CONDITION
d) DB_DOMAIN

ANSWER: d) DB_DOMAIN

####___ used to sort the data in the table

a) Order by clause b) Group by clause c) Aggregate functions d) Sequence

ANSWER: a) Order by clause

__ clause can be used to find unique values in situations to which __ apply.

a) HAVING, DISTINCT does not b) HAVING, DISTINCT c) GROUP BY, DISTINCT d) HAVING, GROUP BY

ANSWER: a) HAVING, DISTINCT does not.

Which of the following is not a valid SQL data type?

a) NUMBER b) DATE c) LONG d) FRACTION

ANSWER: d) FRACTION

__ condition can’t contain sub queries or sequence.

a) Check b) Unique c) References d) Index

ANSWER: a) Check

What is true about join?

a) You can join a maximum of two tables b) You can join a maximum of two columns through C) You can join two or more tables d) None of the above

ANSWER: You can join two or more tables.

Joining a table to itself is referred to as ____.

a) Self-join b) Cross-join c) Outer Join d) Full Outer Join

ANSWER: a) Self-join

A sub query is a form of an SQL statement that appears __ another SQL statement.

a) At the start of b) Inside c) Outside d) After

ANSWER: b) Inside

The____ data types are used to store binary data.

a) Raw b) LONG c) bfile d) rowid

ANSWER: a) Raw

A____ level constraint must be applied if data constraint spans across multiple columns in a table.

a) Table b) Row c) Column d) Database

ANSWER: a) Table

__ constraint can only applied at column level.

a) NOT NULL b) CHECK c) UNIQUE d) PRIAMRY KEY

ANSWER: a) NOT NULL

EXTRACT() function returns _______.

a) a value extracted from a date or an interval value b) number of columns in a table c) number of tables in a database d) number of rows in a table

ANSWER: a) a value extracted from a date or an interval value

Which of the following is a string function?

a) UPPER( ) b) FLOOR( ) c) LEAST( ) d) ABS( )

ANSWER: a) UPPER( )

VSIZE( ) function returns _______.

a) number of bytes in the internal representation of an expression b) number of rows where expr is not null c) largest integer value d) returns a Unicode string

ANSWER: a) number of bytes in the internal representation of an expression.