SQL Server Interview Questions
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.
There are some rules of database normalization, which is commonly known as Normal
From, and they are:
Page 1 of 10
Using these steps, the redundancy, anomalies, inconsistency of the data in the data-
base can be removed.
o INNER JOIN
o LEFT OUTER JOIN
o RIGHT OUTER JOIN
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.
Page 2 of 10
failed. Some of the most commonly used constraints are NOT NULL, PRIMARY
KEY, FOREIGN KEY, AUTO_INCREMENT, UNIQUE KEY, etc.
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.
3) We can use the WHERE clause in the We cannot use the WHERE clause with
DELETE command. TRUNCATE.
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.
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.
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.
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.
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:
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.
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.
SQL provides seven (7) aggregate functions, which are given be-
low:
Page 7 of 10
o LAST(): This function is used to returns the last value of an ex-
pression.
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.
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:
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.
1 to 1 , 1 to Many ,
Page 10 of 10