0% found this document useful (0 votes)
25 views10 pages

SQL Server Interview Questions

1) RDBMS stands for Relational Database Management System and is based on a relational model that facilitates manipulating data stored in tables using relational operators. Examples include Microsoft Access, MySQL, SQL Server, and Oracle database. 2) SQL is the standard language used to maintain relational databases and perform operations like data manipulation, database creation, deletion, and row fetching and modification. 3) Normalization organizes fields and tables to minimize redundancy and dependency by following normal forms like 1NF, 2NF, 3NF and BCNF which remove anomalies and inconsistencies from databases.

Uploaded by

gk.mobm33
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
25 views10 pages

SQL Server Interview Questions

1) RDBMS stands for Relational Database Management System and is based on a relational model that facilitates manipulating data stored in tables using relational operators. Examples include Microsoft Access, MySQL, SQL Server, and Oracle database. 2) SQL is the standard language used to maintain relational databases and perform operations like data manipulation, database creation, deletion, and row fetching and modification. 3) Normalization organizes fields and tables to minimize redundancy and dependency by following normal forms like 1NF, 2NF, 3NF and BCNF which remove anomalies and inconsistencies from databases.

Uploaded by

gk.mobm33
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 10

SQL Server Interview Questions

1. What is RDBMS?
RDBMS stands for Relational Database Management System. It is a database manage-
ment system based on a relational model. It facilitates you to manipulate the data stored
in the tables by using relational operators. RDBMS stores the data into the collection of
tables and links those tables using the relational operators easily whenever required.
Examples of relational database management systems are Microsoft Access, MySQL,
SQL Server, Oracle database, etc.

2.What is SQL?
SQL stands for the Structured Query Language. It is the stan-
dard language used to maintain the relational database and per-
form many different data manipulation operations on the data.
SQL was initially invented in 1970. It is a database language
used for database creation, deletion, fetching and modifying
rows, etc. sometimes, it is pronounced as 'sequel.' We can also
use it to handle organized data comprised of entities (variables)
and relations between different entities of the data.

3. What is Normalization in a Database?


Normalization is used to minimize redundancy and dependency by organizing fields and
table of a database.

There are some rules of database normalization, which is commonly known as Normal
From, and they are:

o First normal form(1NF)


o Second normal form(2NF)
o Third normal form(3NF)
o Boyce-Codd normal form(BCNF)

Page 1 of 10
Using these steps, the redundancy, anomalies, inconsistency of the data in the data-
base can be removed.

4. What is the primary use of Normalization?


Normalization is mainly used to add, delete or modify a field that can be made in a sin-
gle table. The primary use of Normalization is to remove redundancy and remove the in-
sert, delete and update distractions. Normalization breaks the table into small partitions
and then links them using different relationships to avoid the chances of redundancy.

5. Which are joins in SQL? Name the most commonly used


SQL joins?
SQL joins are used to retrieve data from multiple tables into a meaningful result set. It is
performed whenever you need to fetch records from two or more tables. They are used
with SELECT statement and join conditions.

The following are the most commonly used joins in SQL:

o INNER JOIN
o LEFT OUTER JOIN
o RIGHT OUTER JOIN

6. What is a "TRIGGER" in SQL?


A trigger is a set of SQL statements that reside in a system catalog. It is a special
type of stored procedure that is invoked automatically in response to an event. It al-
lows us to execute a batch of code when an insert, update or delete command is run
against a specific table because the trigger is the set of activated actions whenever
DML commands are given to the system.

SQL triggers have two main components one is action, and another is an event.
When certain actions are taken, an event occurs as a result of those actions.

7. What is a constraint? Tell me about its various levels.


The constraint is used to specify the rule and regulations that allows or restricts what
values/data will be stored in the table. It ensures data accuracy and integrity inside
the table. It enforces us to store valid data and prevents us from storing irrelevant
data. If any interruption occurs between the constraint and data action, the action is

Page 2 of 10
failed. Some of the most commonly used constraints are NOT NULL, PRIMARY
KEY, FOREIGN KEY, AUTO_INCREMENT, UNIQUE KEY, etc.

The following syntax illustrates us to create a constraint for a table:

8. What is the difference between DELETE and TRUNCATE


statements in SQL?
The main difference between them is that the delete statement deletes data without re-
setting a table's identity, whereas the truncate command resets a particular table's iden-
tity. The following comparison chart explains it more clearly:

No DELETE TRUNCATE
.

1) The delete statement removes single or The truncate command deletes the whole
multiple rows from an existing table de- contents of an existing table without the table
pending on the specified condition. itself. It preserves the table structure or
schema.

2) DELETE is a DML command. TRUNCATE is a DML command.

3) We can use the WHERE clause in the We cannot use the WHERE clause with
DELETE command. TRUNCATE.

4) DELETE statement is used to delete a TRUNCATE statement is used to remove all


row from a table. the rows from a table.

5) DELETE is slower because it main- TRUNCATE statement is faster than


tained the log. DELETE statement as it deletes entire data
at a time without maintaining transaction
logs.

6) You can roll back data after using the It is not possible to roll back after using the
DELETE statement. TRUNCATE statement.

Page 3 of 10
7) DELETE query takes more space. TRUNCATE query occupies less space.

9. What is the ACID property in a database?


The ACID properties are meant for the transaction that goes through a different group of
tasks. A transaction is a single logical order of data. It provides properties to maintain
consistency before and after the transaction in a database. It also ensures that the data
transactions are processed reliably in a database system.

The ACID property is an acronym for Atomicity, Consistency, Isolation, and Durability.

Atomicity: It ensures that all statements or operations within the transaction unit must
be executed successfully. If one part of the transaction fails, the entire transaction fails,
and the database state is left unchanged. Its main features are COMMIT, ROLLBACK,
and AUTO-COMMIT.

Consistency: This property ensures that the data must meet all validation rules. In sim-
ple words, we can say that the database changes state only when a transaction will be
committed successfully. It also protects data from crashes.

Isolation: This property guarantees that the concurrent property of execution in the
transaction unit must be operated independently. It also ensures that statements are
transparent to each other. The main goal of providing isolation is to control concurrency
in a database.

Durability: This property guarantees that once a transaction has been committed, it
persists permanently even if the system crashes, power loss, or failed.

10. Is a blank space or zero the same as a NULL value?


No. The NULL value is not the same as zero or a blank space. The following points ex-
plain their main differences:

o A NULL value is a value, which is 'unavailable, unassigned, unknown or not ap-


plicable.' It would be used in the absence of any value. We can perform arith-
metic operations on it. On the other hand, zero is a number, and a blank space is
treated as a character.
o The NULL value can be treated as an unknown and missing value, but zero and
blank spaces differ from the NULL value.

Page 4 of 10
o We can compare a blank space or a zero to another blank space or a zero. On
the other hand, one NULL may not be the same as another NULL. NULL indi-
cates that no data has been provided or that no data exists.

11. What are functions and their usage in SQL?


SQL functions are simple code snippets that are frequently used and re-used in data-
base systems for data processing and manipulation. Functions are the measured val-
ues. It always performs a specific task. The following rules should be remembered while
creating functions:

o A function should have a name, and the name cannot begin with a special char-
acter such as @, $, #, or other similar characters.
o Functions can only work with the SELECT statements.
o Every time a function is called, it compiles.
o Functions must return value or result.
o Functions are always used with input parameters.

SQL categories the functions into two types:

o User-Defined Function: Functions created by a user based on their needs are


termed user-defined functions.
o System Defined Function: Functions whose definition is defined by the system
are termed system-defined functions. They are built-in database functions.

SQL functions are used for the following purposes:

o To perform calculations on data


o To modify individual data items
o To manipulate the output
o To format dates and numbers
o To convert data types

12. How do we use the DISTINCT statement? What is its


use?

Page 5 of 10
The DISTINCT keyword is used to ensure that the fetched value always has unique val-
ues. It does not allow to have duplicate values. The DISTINCT keyword is used with the
SELECT statement and retrieves different values from the table's column. We can use it
with the help of the following syntax:

SELECT DISTINCT column_lists FROM table_name WHERE [condition];

Suppose we have a table 'customer' containing eight records in which the name column
has some duplicate values.

If we want to get the name column without any duplicate values, the DISTINCT keyword
is required. Executing the below command will return a name column with unique
values.

13. What is the default ordering of data using the ORDER


BY clause? How could it be changed?
The ORDER BY clause is used to sort the table data either in ascending or descending
order. By default, it will sort the table in ascending order. If we want to change its default
behavior, we need to use the DESC keyword after the column name in the ORDER BY
clause.

14. What is the difference between the WHERE and HAV-


ING clauses?
The main difference is that the WHERE clause is used to filter records before any
groupings are established, whereas the HAVING clause is used to filter values from a
group. The below comparison chart explains the most common differences:

WHERE HAVING

This clause is implemented in row opera- This clause is implemented in column op-
tions. erations.

It does not allow to work with aggregate It can work with aggregate functions.
functions.

This clause can be used with the SE- This clause can only be used with the SE-
LECT, UPDATE, and DELETE state- LECT statement.

Page 6 of 10
ments.

15. How many Aggregate functions are available


in SQL?
The aggregate function is used to determine and calculate several val-
ues in a table and return the result as a single number. For example,
the average of all values, the sum of all values, and the maximum and
minimum value among particular groupings of values.

The following syntax illustrates how to use aggregate functions:

1. function_name (DISTINCT | ALL expression)

SQL provides seven (7) aggregate functions, which are given be-
low:

o AVG(): This function is used to returns the average value from


specified columns.
o COUNT(): This function is used to returns the number of table
rows, including rows with null values.
o MAX(): This function is used to returns the largest value among
the group.
o MIN(): This function is used to returns the smallest value among
the group.
o SUM(): This function is used to returns the total summed
values(non-null) of the specified column.
o FIRST(): This function is used to returns the first value of an ex-
pression.

Page 7 of 10
o LAST(): This function is used to returns the last value of an ex-
pression.

16. What are the subsets of SQL?


The following are the four significant subsets of the SQL:

o Data definition language (DDL): It defines the data structure


that consists of commands like CREATE, ALTER, DROP, etc.
o Data manipulation language (DML): It is used to manipulate
existing data in the database. The commands in this category are
SELECT, UPDATE, INSERT, etc.
o Data control language (DCL): It controls access to the data
stored in the database. The commands in this category include
GRANT and REVOKE.
o Transaction Control Language (TCL): It is used to deal with the
transaction operations in the database. The commands in this
category are COMMIT, ROLLBACK, SET TRANSACTION, SAVE-
POINT, etc.

17. What is a primary key?


A primary key is a field or the combination of fields that uniquely
identify each record in the table. It is one of a special kind of
unique key. If the column contains a primary key, it cannot be
null or empty. A table can have duplicate columns, but it cannot
have more than one primary key. It always stores unique values
into a column. For example, the ROLL Number can be treated as
the primary key for a student in the university or college.

Page 8 of 10
18. What is a foreign key?
The foreign key is used to link one or more tables together. It is also
known as the referencing key. A foreign key is specified as a key that is
related to the primary key of another table. It means a foreign key field
in one table refers to the primary key field of the other table. It identi-
fies each row of another table uniquely that maintains the referential
integrity. The primary key-foreign key relationship is a very crucial re-
lationship as it maintains the ACID properties of the database some-
times. It also prevents actions that would destroy links between the
child and parent tables.

19. What is Referential Integrity?

20. What is a unique key?


A unique key is a single or combination of fields that ensure all values
stores in the column will be unique. It means a column cannot stores
duplicate values. This key provides uniqueness for the column or set of
columns. For example, the email addresses and roll numbers of stu-
dent's tables should be unique. It can accept a null value but only one
null value per column. It ensures the integrity of the column or group
of columns to store different values into a table.

21. What is the difference between a pri-


mary key and a unique key?
The primary key and unique key both are essential constraints of the
SQL. The main difference among them is that the primary key identi-

Page 9 of 10
fies each record in the table. In contrast, the unique key prevents du-
plicate entries in a column except for a NULL value. The following
comparison chart explains it more clearly:

Primary Key Unique Key

The primary key act as a unique identi- The unique key is also a
fier for each record in the table. unique identifier for records
when the primary key is not
present in the table.

We cannot store NULL values in the pri- We can store NULL value in
mary key column. the unique key column, but
only one NULL is allowed.

We cannot change or delete the pri- We can modify the unique key
mary key column values. column values.

22. How many types of Relationships


can exist between 2 tables of a DB

1 to 1 , 1 to Many ,

23. How a Many to Many Relationship is


Normalized?

Page 10 of 10

You might also like