100% found this document useful (1 vote)
47 views

SQL Interview Questions & Answers

The document discusses various SQL concepts including: 1. Databases are used to store data in an organized manner. DBMS is software used to manage databases. RDBMS is a type of DBMS that stores data in tables and uses SQL. 2. Primary keys uniquely identify records while foreign keys link tables. Other concepts covered include joins, normalization, single vs multi-row functions, and DML statements like INSERT, UPDATE, DELETE. 3. The document provides examples to illustrate differences between concepts like WHERE and HAVING clauses, TRUNCATE and DROP commands, and ORDER BY clause functionality. SQL commands like CREATE TABLE, ALTER TABLE, SELECT are also briefly explained.

Uploaded by

Vignesh Varadhan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
47 views

SQL Interview Questions & Answers

The document discusses various SQL concepts including: 1. Databases are used to store data in an organized manner. DBMS is software used to manage databases. RDBMS is a type of DBMS that stores data in tables and uses SQL. 2. Primary keys uniquely identify records while foreign keys link tables. Other concepts covered include joins, normalization, single vs multi-row functions, and DML statements like INSERT, UPDATE, DELETE. 3. The document provides examples to illustrate differences between concepts like WHERE and HAVING clauses, TRUNCATE and DROP commands, and ORDER BY clause functionality. SQL commands like CREATE TABLE, ALTER TABLE, SELECT are also briefly explained.

Uploaded by

Vignesh Varadhan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

INTERVIEW QUESTIONS ON SQL

1. WHAT IS DATABASE ?
> Database is a place or medium which is used to store data in systematic and organized
manner.

2. WHAT IS DBMS?
> It is a software which is used to maintain and manage the database.
>security and authorization are the 2 main features in dbms.
> we use query language to communicate or interact with dbms.
> dbms stores the data in the form of files.

3. DIFFERENCE BETWEEN DBMS & RDBMS


DBMS
> It is a software which is used to maintain and manage the database.
>security and authorization are the 2 main features in dbms.
> we use query language to communicate or interact with dbms.
> dbms stores the data in the form of files.
RDBMS
> It is a type of dbms software which is used to maintain and manage the database.
>security and authorization are the 2 main features in dbms.
> we use Structured query language to communicate or interact with dbms.
> dbms stores the data in the form of tables.

4. DIFFERENCE BETWEEN PRIMARY KEY & FOREIGN KEY


PRIMARY KEY
> The primary key is a constraint that is used to identify a record uniquely from the table.
i) Primary key will not accept duplicate or repeated values.
ii) Primary key will not accept NULL values.
iii) Primary key is a combination of Unique and Not Null constraints.
iv) In a table we can have only one primary key.
v) Primary Key is not mandatory but recommended to have one in a table.
FOREIGN KEY
> A foreign key is a constraint that is used to establish a connection between 2 tables.
i) Foreign keys can accept duplicate or repeated values.
ii) Foreign keys can accept Null values.
iii) Foreign key is not a combination of Unique and Not Null constraints.
iv) In a table we can have any number of Foreign keys.
v) To be a Foreign key it should be a Primary key in its own table.
vi) Foreign key is present in the Child table but belongs to the Parent table.
vii) Foreign key also known as 'REFERENCIAL INTEGRITY CONSTRAINT'.

5. DIFFERENCE BETWEEN UNIQUE & DISTINCT CLAUSE


UNIQUE
Unique is a constraint that is given for a column where the column should not accept
duplicate or repeated values.
DISTINCT CLAUSE
It is used to remove the duplicated or repeated values from the result table.
6. WHAT IS SUBQUERY & EXPLAIN THE PROCEDURE OF EXECUTION
> A Query written inside another query is known as subquery.
PROCEDURE
1. In the Subquery, we have a minimum of 2 queries.
a. Outerquery
b. Innerquery / Subquery. 2) In
subquery the inner query starts the execution and gives you an output. 3) The output
of Innerquery is given as an input to the outer query.
4) After getting the input from the inner query, the outer query starts the execution and
generates the result.
5) Therefore we can say that the Outer query is dependent on Inner Query. (Because if outer
query wants to execute the input is given by the Inner query)

7. WHAT ARE THE TYPES OF JOINS AND EXPLAIN EACH?


> The process of retriving the data from multiple tables simultaneously is known as joins.
TYPES OF JOINS
1.CARTESIAN JOIN /CROSS JOIN
2. INNER JOIN /EQUI JOIN
3. OUTER JOIN
a. left outer join
b. right outer join
c. full outer join
4. NATURAL JOIN
5. SELF JOIN

8. WHAT IS NORMALIZATION?
> THE DECOMPOSITION OF LARGER TABLE INTO SEVERAL SMALLER TABLES IN ORDER TO
REMOVE ‘REDUNDANCY’ AND ‘ANOMALY’ BY IDENTIFYING THEIR FUNCTIONAL
DEPENDENCIES.

9. WHAT IS TABLE?
> TABLE IS A LOGICAL ORGANIZATION OF ROWS AND COLUMNS.

10. WHAT IS SQL?


> SQL stands for Structured Query Language , and it is used to communicate with the
Database.This is a standard language used to perform tasks such as retrieval, updating,
insertion and deletion of data from a database.

11.DIFFERENCE BETWEEN WHERE AND HAVING CLAUSE

WHERE CLAUSE: *IT IS USED TO FILTER THE RECORDS.


* IT EXECUTES ROW BY ROW.

* IT EXECUTES BEFORE GROUP BY CLAUSE.

* WE CAN’T USE MULTIROW FUNCTIONS IN WHERE CLAUSE

*WE CAN USE COLUMN NAMES IN WHERE CLAUSE

HAVING CLAUSE: *IT IS USED TO FILTER THE GROUPS.


* IT EXECUTES GROUP BY GROUP.
* IT EXECUTES AFTER GROUP BY CLAUSE.

* WE CAN USE MULTIROW FUNCTIONS IN HAVING CLAUSE

*WE CAN’T USE COLUMN NAMES IN HAVING CLAUSE.

12.DIFFERENCE BETWEEN SINGLE ROW AND MULTI ROW FUNCTION


SINGLE ROW FUNCTION: IT EXECUTES ROW BY ROW.
*IF WE PASS N NUMBER OF INPUTS IT GIVES N NUMBER OF OUTPUTS.
MULTI ROW FUNCTION: IT EXECUTES IN GROUP
*IF WE PASS N NUMBER OF INPUTS IT GIVES SINGLE OUTPUT.

13.DIFFERENCE BETWEEN DELETE & TRUNCATE COMMANDS.


TRUNCATE: IT IS USED TO REMOVE ALL THE RECORDS FROM THE TABLE PERMENANTLY.
DELETE: IT IS USED TO REMOVE PARTICULAR RECORD FROM THE TABLE.

14. WHAT IS CONSTRAINT AND TYPES?


> CONSTRAINTS ARE THE RULES GIVEN TO A COLUMN TO VALIDATE THE DATA.
TYPES:
*UNIQUE
* NOT NULL
* CHECK
* PRIMARY KEY
* FOREIGN KEY

15. WHAT IS ALIAS COMMAND?

> ALIAS IS USED TO GIVE ALTERNATE NAME TO A COLUMN NAME OR AN EXPRESSION.

> ALIAS NAME CAN BE USED WITH OR WITHOUT USING ‘AS’ KEYWORD.

16. DIFFERENCE BETWEEN TRUNCATE AND DROP

TRUNCATE: IT IS USED TO REMOVE ALL THE RECORDS FROM THE TABLE PERMENANTLY

DROP: DROP IS USED TO DELETE THE TABLE FROM THE DATABASE.

17. WHAT IS THE SYNTAX TO CREATE A TABLE

> CREATE TABLE TABLE_NAME

COLUMN_NAME1 DATATYPE CONSTRAINTS,

COLUMN_NAME2 DATATYPE CONSTRAINTS,

COLUMN_NAME_N DATATYPE CONSTRAINTS

);

18. WHICH OPERATOR IS USED IN QUERY FOR PATTERN MATCHING?

> LIKE OPERATOR.

SYNTAX: COLUMN_NAME LIKE ‘PATTERN_TO_MATCH’;


19. WHAT ARE DML STATEMENTS?

> DATA MANIPULATION LANGUAGE IS USED TO MANIPULATE THE TABLE SUCH AS


INSERTION OF RECORDS AND UPDATING AND DELETION OF RECORDS FROM THE TABLE.

WE HAVE 3 DML STATEMENTS:

1.) INSERT: THIS STATEMENT IS USED TO INSERT THE RECORDS INTO THE TABLE.
2.) UPDATE: THIS STATEMENT IS USED TO MODIFY THE RECORDS INTO THE TABLE.
3.) DELETE: THIS STATEMENT IS USED TO DELETE THE PARTICULAR RECORDS FROM THE TABLE.

20. WHY WE USE COMMIT STATEMENT.

> COMMIT STATEMENT IS USED TO SAVE THE TRANSACTION INTO THE DATABASE.

21. WHAT IS ORDER BY CLAUSE ?

> ORDER BY CLAUSE IS USED TO ARRANGE THE RECORDS EITHER IN ASCENDING OR


DESECINDING ORDER.

> BY DEFAULT ORDER BY CLAUSE ARRANGES RECORDS IN ASCENDING ORDER.

> ORDER BY CLAUSE IS THE ONLY CLAUSE WHICH EXECUTES AFTER SELECT CLAUSE.

You might also like