Interview Questions on SQL

1. What is DBMS?

A database Management System is a collection of programs that enables you to store, modify, and extract information from a database.

2. What is RDBMS?

RDBMS stands for Relational Database Management System. RDBMS data is structured in database tables, fields and records.

3. What is cursor?

A cursor is a temporary work area created in the system memory when a SQL statement is executed. A cursor contains information on a select statement and the rows of data accessed by it.

4. what is Index?

An index can be created in a table to find data more quickly and efficiently.
ex:- CREATE INDEX index_name
ON table_name (column_name)

5. What is view?

In SQL, a view is a virtual table based on the result-set of an SQL statement. A view contains rows and columns, just like a real table.

6. What is trigger?

A database trigger is procedural code that is automatically executed in response to certain events on a particular table in a database.

7. What are the DDL statements?

1. CREATE - to create objects in the database
2. ALTER - alters the structure of the database
3. DROP - delete objects from the database
4. TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed

8. What are the DML statements?

1. SELECT - retrieve data from the a database
2. INSERT - insert data into a table UPDATE - updates existing data within a table
3. DELETE - deletes all records from a table, the space for the records remain

9. What is subquery?

A subquery is a query that is nested inside a SELECT, INSERT, UPDATE, or DELETE statement.

10. Write a syntax for creating the table?

CREATE TABLE table_name
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),

11. Write a syntax for updating the table?

UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;

12. What is the Difference between delete and truncate?

The DELETE command is used to remove rows from a table. A WHERE clause can be used to only remove some rows. TRUNCATE removes all rows from a table.

13. Explain about Joins?

An SQL JOIN clause is used to combine rows from two or more tables, based on a common field between them. JOIN Types:
1. INNER JOIN - The INNER JOIN selects all rows from both tables if there is a match between the columns in both tables.
2. LEFT OUTER JOIN - The LEFT JOIN keyword returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side when there is no match.
3. RIGHT OUTR JOIN - The RIGHT JOIN keyword returns all rows from the right table (table2), with the matching rows in the left table (table1). The result is NULL in the left side when there is no match.
4. FULL OUTER JOIN - The FULL OUTER JOIN keyword combines the result of both LEFT and RIGHT joins.

14. Write a sql query to find the 4th largest element in the list?

FROM Employee Emp1
WHERE (3) = (
FROM Employee Emp2
WHERE Emp2.Salary > Emp1.Salary)

15. What is Normalization?

Database normalization is the process of organizing the fields and tables of a relational database to minimize redundancy.

16. What is Exception?

An error condition during a program execution is called an exception.

17.What is Primary Key?

The PRIMARY KEY constraint uniquely identifies each record in a database table. A primary key column cannot contain NULL values. Each table can have only ONE primary key.

18. What is Foreign Key?

The ForeignKey is used to maintain relationship between multiple tables. This Key is Primary Key in another table.

18. How to insert values into a table?

INSERT INTO table_name
VALUES (value1,value2,value3,...);

19. Write syntax to delete the tables.

DELETE FROM table_name
WHERE some_column=some_value;

21. What is the use of LIKE Operator?

The LIKE operator is used to search for a specified pattern in a column.
SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern;