0% found this document useful (0 votes)
10 views5 pages

SQL Interview Questions

This document contains questions and answers about SQL. It discusses topics like SQL statements, database concepts, table structures, joins, and more. There are over 30 questions answered in detail providing essential information about SQL.

Uploaded by

gharshanatalele
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
10 views5 pages

SQL Interview Questions

This document contains questions and answers about SQL. It discusses topics like SQL statements, database concepts, table structures, joins, and more. There are over 30 questions answered in detail providing essential information about SQL.

Uploaded by

gharshanatalele
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 5

SQL Interview Questions

Q1. What is SQL?

Ans: SQL stands for structured query language. It is a standard language for accessing and
manipulating databases. SQL can execute queries like create, insert, delete, update, etc. on database

Q2. What is database?

Ans: A database is an organized collection of data so that it can be easily accessed and managed.

Q3. What are the different types of statements supported by SQL?

Ans: There are 5 types of SQL statements or commands:

1) DDL (Data definition language): DDL changes the structure of table. DDL commands are:
create, alter, drop, truncate
2) DML (Data manipulation language): DML commands are used to modify database. DML
commands are: insert, update, delete
3) DCL (Data control language): DCL is used to manage access rights, permissions and security.
DCL commands are: grant, revoke
4) TCL (transaction control language): TCL commands are used to manage transactions. They can
be only used with DML commands. TCL commands are: commit, rollback, savepoint.
5) DQL (data query language): DQL is used to fetch the data from database. DQL queries are:
select.

Q4. What is DBMS and RDBMS?

Ans: DBMS and RDBMS both are used to store information in physical database. DBMS applications
store data as file. While RDBMS applications store data in tabular form.

Q5. What is primary key?

Ans: Primary key is the constraint that uniquely identifies each record in a table. It cannot contain
null values. A table can have only one primary key.

Q6. What is foreign key?

Ans: Foreign key is a field in one table that refers to the primary key in another table. The table with
foreign key is called child table.

Q7. What is difference between primary key and unique key?

Ans: primary key is the unique, not null key that uniquely identifies every record in the table. While,
the unique key is a single column or combination of columns to uniquely identify database records.

Primary key does not allow null values while unique key allows storing null value.

Q8. What is the join in SQL?

Ans: Join clause is used to combine rows from two or more tables. Types of join: inner join, outer
join, cross join, self join

Q9. What is the difference between delete, drop and truncate?


Ans: delete is a DML command which is used to delete one or more records from the table. Drop is a
DDL command which is used to drop the whole table. Truncate is a DDL commands which is used to
delete all the records from the table but not the table.

Q10. What is difference between union and union all in SQL?

Ans: Union operator is used to combine two or more rows. it removes the duplicate rows from the
table. Union all is used to combine two or more rows but it does not remove duplicate records.

Q11. What is difference between having clause and where clause?

Ans: The main difference between them is that where clause is used to specify a condition for
filtering records before any groupings are made while having clause is used to specify a condition
from a group.

Q12. What is transaction in SQL?

Ans: Transactions group a set of tasks into a single execution unit. Each transaction begins with a
specific job and ends when all the tasks are successfully executed.

Q13. What is difference between a database and a schema?

Ans: Database is an organized collection of data so that it can be easily accessed and managed,
whereas schema is a logical representation of the database.

Q14. What is the purpose of group by clause?

Ans: group by clause is used to arrange identical data into groups with the help of aggregate
functions. The purpose of group by clause is to arrange the rows which have same values in a group.

Q15. What is the difference between char and varchar datatypes?

Ans: char datatype is used to store character strings of fixed length. It takes extra memory space as it
leaves blank spaces to reach to the assigned length. Whereas, varchar datatype is used to store
character strings of variable length. It does not take extra memory space. The storage size of char
datatype is n bytes i.e. set length while the storage size of varchar is actual length of entered string in
bytes.

Q16. What is stored procedure in SQL?

Ans: A stored procedure is a prepared code that can be saved and can be used over and over again.
write a sql query and if it has to use again save it as a stored procedure and then call it to execute it.

Q17. What is the sub query in SQL?

Ans: A subquery is a query within another query. The outer query is called as main query and the
inner query is called as subquery.

Q18. What is the view in SQL?

Ans: A view is the virtual table that is based on the result of the SQL query.

Q19. What is the difference between cross join and inner join?

Ans: cross join is the full cartesian product of two sides of a join whereas, inner join is the
intersection i.e. reduction of cartesian product.
Q20. What is the purpose of commit statement?

Ans: Commit is the TCL command which is used to permanently save the changes. The database
cannot regain its previous state after execution of commit statement.

Q21. What is the purpose of rollback statement?

Ans: Rollback is TCL command which is used to undo the transactions that have not been saved in
the database.

Q22. What is the purpose of the null value in SQL?

Ans: A field with null value is one that has been left blank during filling records. If a field in a table is
optional, it is possible to insert or update a new record without adding a value to this field. Then, the
field will be saved with null value.

Q23. What is the purpose of distinct keyword?

Ans: Distinct keyword is used to return only distinct values.

Q24. What is the constraint? Give the types of constraints in SQL.

Ans: Constraints are the rules given to columns. They can be specified when the table is created.
Types:

1) Not null: ensures that column cannot have null value.


2) Unique: ensures all values in column are different.
3) Primary key: It uniquely identifies each row in table.
4) Foreign key: refers to the primary key of another table.
5) Check: ensures that values in column satisfies the specific condition.
6) Default: sets a default value to column.
7) Identity: used to create and retrieve data from database quickly.

Q25. What is the TRIGGER and its purpose?

Ans: the trigger is a special procedure which cannot be called directly like a stored procedure. Trigger
is called automatically when a data modification occurs. Trigger allows you to specify actions that
should be executed automatically when a specific event occurs.

Q26. What is the difference between unique constraint and a unique index?

Ans: A unique index ensures that the values in the index key columns are unique. Whereas, a unique
constraint ensures that no duplicate values can be inserted into the columns.

Q27. What is the difference between union and join operator?

Ans: Union operation is only performed on tables that contains same number of columns with same
datatype. Whereas, join operation can be performed on the tables that has at least one common
field between them.

Q28. What is the purpose of grant statement?

Ans: Grant statement is used to grant permissions to modify and retrieve data.

Q29. What is the difference between natural join and inner join?
Ans: Natural join joins two tables based on the same attribute name and datatypes. The resulting
table will contain all the attributes of both tables eliminating the duplicate columns. Inner join
combines data from two or more tables base don the specified condition. The resulting table of inner
join will contain all attributes from both tables including duplicate columns also.

Q30. What is a self join?

Ans: Self join joins the table with itself. It allows to combine rows from the same table based on the
specific condition.

Q31. What is an ALIAS command in SQL?

Ans: SQL aliases are used to give a table or a column a temporary name. An alias is created with AS
keyword. Ex. Select CustomerId AS ID from customers;

Q32. Why are SQL functions used?

Ans: The SQL functions can be used to calculate statistics such as number of rows in table, total
value of a specific column, the average value of a column, the min or max value from the column,
etc.

Q33. How many aggregate functions are available in SQL?

Ans: 5 as count(), sum(), avg(), min(), max().

Q34. What is the use of like, in between, and is null in SQL?

Ans: like is used to check if the column value is similar to specified character pattern.

In between is used to check if the column value Is equal to any one of a specified set of values.

Is null means the column does not exist.

Q35. Explain the difference between aggregate function and scalar function.

Ans: Aggregate functions are used to do operations from values of the column and returns a single
value. Whereas, scalar functions are based on user inputs which returns single value.

Q36. What is normalization in SQl?

Ans: normalization is the process of organizing data in a database to minimize redundancy and
dependency. It involves breaking down a table into smaller tables and establishing relations between
them.

Q37. What is the difference between clustered and non-clustered index?

Ans: a clustered index determines the physical order of data in table. A table can have only one
clustered index. It changes the way data is stored and can be created on only one column.

A non-clustered index does not affect the physical order of the data in table. It is stored separately
and contains pointer to the actual data. A table can have multiple non-clustered index.

Q38. What is the correlated subquery?

Ans: a correlated subquery is a subquery that refers to a column from the outer query. It executes
once for each row.

Q39. What is difference between IN and EXISTS operators?


Ans: IN operator checks for a value within a set of values or result of the subquery.

EXISTS operator checks the existence of rows retuned by the subquery.

Q40. What is the purpose of the top or limit clause?

Ans: top or limit clause is used to limit the number of rows returned by a query.

Q41. What is data warehouse?

Ans: a data warehouse is a large, centralised repository which stores and manages data from various
sources. It is designed for efficient reporting, analysis and business intelligence purposes.

Q42. How to find date, time in SQL?

Ans: the simplest way to get current time and date is by using NOW() function. Another way is by
using current_timestamp() function.

Date_format() function can be used to return a customised format of date and time.

You might also like