0% found this document useful (0 votes)
8 views13 pages

DBSQL 5

This document contains a comprehensive set of SQL Server interview questions and answers, covering topics such as SQL Server definitions, commands, database creation, and key concepts like primary and foreign keys. It also discusses the differences between SQL and PL/SQL, properties of RDBMS, and various types of relationships in databases. Additionally, it provides insights into database normalization, functions, and aggregate functions in SQL Server.

Uploaded by

tasamr32
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views13 pages

DBSQL 5

This document contains a comprehensive set of SQL Server interview questions and answers, covering topics such as SQL Server definitions, commands, database creation, and key concepts like primary and foreign keys. It also discusses the differences between SQL and PL/SQL, properties of RDBMS, and various types of relationships in databases. Additionally, it provides insights into database normalization, functions, and aggregate functions in SQL Server.

Uploaded by

tasamr32
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

PART-1

SQL SERVER
Interview Questions
[EXCLUSIVE NOTES]
[SAVE AND SHARE]
Curated By- HIMANSHU KUMAR(LINKEDIN)https://www.linkedin.com/in/himanshukumarmahuri

1. What is SQL Server


2. List and explain types of commands used in SQL Server.
3. Explain the method of creating a database in SQL Server.
4. What is SQL?
5. What is the latest version of SQL Server?
6. Explain PL/SQL.
7. Differentiate between SQL and PL/SQL.
8. Explain a Relational Database Management System (RDBMS).
9. List out properties of RDBMS.
10.What do you understand about a database table?
11.Tell the syntax for creating a table in SQL Server with an example.
12.Write down the syntax for deleting a table in SQL Server.
13.Tell the syntax for updating a table in the SQL Server.
14.Explain different kinds of relationships in SQL Server.
15.Explain the primary key in SQL Server.
16.What is a foreign key?
17.Name the TCP/IP Port on which SQL Server runs.
18.Explain database normalization and list its forms.
19.Explain functions in SQL Server.
20.Explain Aggregate functions in SQL Server.

pg. 1 HIMANSHU KUMAR (LINKEDIN)


PART-1

1. What is SQL Server?


Answer: SQL Server is one of the leading relational database
management systems developed by Microsoft. It enables other
applications running on the same computer as the SQL Server
or other remote computers to store and retrieve data from a
relational database.

2. List and explain types of commands used in


SQL Server.
Answer: SQL Server supports four different types of
commands, as given below:

• Data Definition Language (DDL):

We use DDL commands in SQL Server to deal with the structure


of entities or objects. There are three DDL commands in SQL
Server:

• Create: This command creates an object or entity.


• Alter: It makes changes in an object or entity.
• Drop: It deletes an object or entity.

Here, an object or an entity is a database, trigger, table, view,


etc.

• Data Manipulation Language (DML):

DML commands in SQL Server are used to perform


manipulations on the data stored in entities, like a table, view,
etc. The three DML commands in SQL Server are:

• Insert: It adds new data into a table. Also, this command


supports the insertion of bulk data into a table.
• Delete: This command deletes the specific data from the
table.
• Update: It updates the values of data in a table.

pg. 2 HIMANSHU KUMAR (LINKEDIN)


PART-1

• Data Control Language (DCL):

In SQL Server, we use DCL commands to ensure the security of


the data stored in objects or entities. Two DCL commands in
SQL Server are:

• Grant: It grants database access permission to a user.


• Revoke: This command takes back the database access
permission from a user.
• Transactional Control Language (TCL):

We use TCL commands in SQL Server to manage transactions.


Three TCL commands in SQL Server are:

• Commit: It saves a transaction in SQL Server permanently.


• Rollback: This TCL command undoes all changes made to
the data in a database made before committing.
• Save Tran: It saves a transaction in SQL Server and rolls it
back to the desired point.

3. Explain the method of creating a database in


SQL Server.
• Answer: In computer programming, a database is a well-
organized collection of data. Alternatively, a database is a
set of various components used for storing data, like
tables, schemas, procedures, etc. Furthermore, Structured
Query Language (SQL) is used in Microsoft SQL Server to
access the data and perform manipulations. We use the
CREATE DATABASE command to create a database in the
SQL Server. The syntax for creating a database in the SQL
Server is:

pg. 3 HIMANSHU KUMAR (LINKEDIN)


PART-1

CREATE DATABASE DatabaseName;

• Example: Consider we need to create a database having


the name Students, so we need to run the following
command:

CREATE DATABASE Students;

• Alternatively, we can use the SQL Server Management


Studio to create a database; go to the left side of the
window, right-click on the Databases option and then click
on the New Database option.

4. What is SQL?
Answer: SQL stands for Structured Query Language. All
relational database management systems use this domain-
specific language to access and manipulate the stored data. It
enables us to perform various tasks, such as creating a
database , retrieving data from a database, creating records,
tables, views, and procedures in a database, etc. All these
operations make use of SQL queries.

5. What is the latest version of SQL Server?


Answer: The latest version is Microsoft SQL Server 2019 which
was released on November 4th 2019.

6. Explain PL/SQL.
Answer: An extension to SQL is PL/SQL. It stands for
Procedural Language extensions to Structured Query
Language. PL/SQL combines the SQL’s data manipulation
feature and the procedural language’s processing power.

pg. 4 HIMANSHU KUMAR (LINKEDIN)


PART-1

Moreover, it is one of the most powerful programming


languages that improve a database’s security and sturdiness.

PL/SQL instructs the Oracle compiler about ‘what actions to


perform using the SQL’s manipulation feature and ‘how to
perform actions’ using the procedural language’s processing
power. As PL/SQL is a procedural language, it involves looping
and conditional statements.

7. List out properties of RDBMS.


Answer: The below list explains the properties of RDBMS:

• All values in a table are atomic.


• Each tuple in a table is unique.
• The sequence of attributes and tuples does not matter in
SQL Server.
• Each attribute in a table should have a unique name.
• All field values in a single column are of the same type.

8. Differentiate between SQL and PL/SQL.


Answer: The below table highlights some of the key
dissimilarities between SQL and PL/SQL:

SQL PL/SQL
It stands for Procedural Language
It stands for Structured Query
extensions to Structured Query
Language.
Language.
SQL executes a single query or PL/SQL executes a block of code or
line of code at a time. multiple lines in one go.

pg. 5 HIMANSHU KUMAR (LINKEDIN)


PART-1

It uses DDL and DML It uses functions, variables,


commands to develop SQL procedures, triggers, and packages to
queries and commands. develop blocks of code.
We use SQL queries to fetch PLSQL is used to develop
data, modify it, or delete it applications that display information
from a database. retrieved using SQL queries.
SQL queries do not support the The PL/SQL syntax allows the use of
use of PL/SQL syntax. SQL queries.

9. Explain a Relational Database Management


System (RDBMS).
Answer: A database management system based on E. F.
Codd’s relational model is called a Relational Database
Management System (RDBMS). Alternatively, RDBMS is a
collection of programs and functionalities that enables
organizations and individuals to interact or communicate with a
relational database. Data in RDBMS is stored in the form of
tuples, i.e., rows and columns. It supports a Structured Query
Language (SQL) to access data from a relational database.

Some vital characteristics of RDBMS are:

• It allows multiple users to access data.


• RDBMS is a robust type of database model that can
handle every data size, whether small, medium, or large-
scale.
• It uses the ACID property to ensure data consistency in a
database.
• RDBMS supports distributed databases and
normalization.

pg. 6 HIMANSHU KUMAR (LINKEDIN)


PART-1

10. What do you understand about a


database table?
Answer: A database table in SQL Server stores all data in the
form of horizontal rows and vertical columns. In addition, a cell
in a table is a unit where a row and a column intersect. A
database table has a specific number of columns or attributes,
whereas it may have any number of rows or tuples. We use DDL
commands for a database table, as a table is an object. The
CREATE command creates a database table, whereas the
DROP command deletes it. Moreover, the ALTER command
modifies the previously defined structure of a table, and the
SELECT command displays data from a table.

11. Tell the syntax for creating a table in SQL


Server with an example.
Answer: The syntax for creating a table in SQL Server is:

CREATE TABLE TableName (ColumnName1 datatype,


ColumnName2 datatype, ...., ColumnNameN datatype) ;

Let us see one example of creating a Students table in SQL


Server. Consider that the Students table has four columns or
attributes, like Name, Student_ID, Mobile_No, and City.

CREATE TABLE Students ( Name varchar(20), Student_ID int,


Mobile_no int, City varchar (20));

After you hit enter, you will get a message ‘Table created
successfully.’

pg. 7 HIMANSHU KUMAR (LINKEDIN)


PART-1

12. Write down the syntax for deleting a table in


SQL Server.
Answer: To delete a table from a database in SQL Server, we
use the DROP command. The syntax of the DROP command is:

DROP TABLE TableName;

Example: Let us consider that we have a table named


Employees, and we need to delete it from a database.

DROP TABLE Employees;

13. Tell the syntax for updating a table in the


SQL Server.
Answer: In SQL Server, we use the ALTER command to update
a table. While creating a table, we specify column names and
their corresponding data types. Also, if we want to add, delete,
or alter any column after creating a table, we can again use the
ALTER command. Therefore, the ALTER command is used in
three different ways, as follows:

• To add a column:

Syntax:

ALTER TABLE table_name ADD column_name datatype;


• To delete a column:

Syntax: ALTER TABLE table_name DROP COLUMN


column_name;

• To modify a column:

pg. 8 HIMANSHU KUMAR (LINKEDIN)


PART-1

Syntax:

ALTER TABLE table_name ALTER COLUMN column_name


datatype;

14. Explain different kinds of relationships in


SQL Server.
Answer: SQL Server supports three kinds of relationships in a
database, as explained below:

• One-to-one:

The one-to-one relation in SQL Server has rare usage. In this


type of relationship, a record or data in one table correlates
with only one record or data present in another table. The
primary advantage of using one-to-one relationships is better
security. For example, consider a Student database. Here, only
one Student_ID is assigned to a single student. Conversely,
each student has a unique ID assigned.

• One-to-many and Many-to-one:

When one record in a table correlates with multiple records in


another table, it is a one-to-many relationship. Conversely, when
multiple records in a table are associated with a single record
in another table, it is a many-to-one relationship. For example,
consider a Customer database. Here, a single customer can
place any number of orders. On the other hand, a specific order
belongs to a single customer.

• Many-to-many:

When multiple records in a table are correlated to multiple


records in another table, it is a many-to-many relationship. For
example, multiple customers can purchase different products.

pg. 9 HIMANSHU KUMAR (LINKEDIN)


PART-1

15. Explain the primary key in SQL Server.


Answer: A primary key in SQL Server can be a single attribute or
field or combination of attributes or fields that uniquely identify
a record or a tuple in a table. There is only one primary key for a
database table. In addition, we can set a primary key for a table
while creating or updating it. However, fields of an attribute or a
combination of attributes that are considered a primary key
cannot be NULL. Below is the syntax for creating a primary key
for a table:

CREATE TABLE table_name ( columnName1 datatype [NULL |


NOT NULL], columnName2 datatype [NULL | NOT NULL], ...
CONSTRAINTS constraint_name PRIMARY KEY (pk_col1,
pk_col2, ...,pk_col_n));

16. What is a foreign key?


Answer: We use a foreign key in SQL Server to connect data
between two different tables; one table will be a child, and
another will be a parent. Alternatively, if an attribute or column
of one table points to the primary key of another table, then that
attribute or column is said to be a foreign key. Let us go
through one example to understand clearly the foreign key.
Consider two tables: Student_record and Student_Marks.

Student_record

Student_ID Stduent_Name Subject_ID Subject


S01 John CC01 Chemistry

pg. 10 HIMANSHU KUMAR (LINKEDIN)


PART-1

S02 Maddy CD01 Computer Science


S03 Williams CE01 Mechanics

Student_Marks

Student_ID Subject_ID Marks


S01 CC01 68
S02 CD01 79
S03 CE01 56

In the above tables, Student_ID is the foreign key. The


Student_ID attribute is a primary key of the table named
Student_record and is present as an attribute in Student_marks.

17. Name the TCP/IP Port on which SQL Server


runs.
Answer: The SQL Server runs on the 1433 TCP/IP port by
default.

18. Explain database normalization and list its forms.


Answer: The technique used to organize data present in a
database to reduce data redundancy is called database
normalization . In addition, database normalization eliminates
Update, Insertion, and Deletion Anomalies from a relation. The
fundamental idea of using the database normalization
technique is to divide a table into smaller ones and connect
them using database relationships. There are six forms of
database normalization, as listed below:

pg. 11 HIMANSHU KUMAR (LINKEDIN)


PART-1

• First Normal Form (1NF)


• Second Normal Form (2NF)
• Third Normal Form (3NF)
• Boyce-Codd Normal Form (BCNF or 4NF)
• Fifth Normal Form (5NF)
• Fifth Normal Form (6NF)

19. Explain functions in SQL Server.


Answer: A function in SQL Server is analogous to a function in
programming languages. It is a sequence of SQL statements
written to accomplish a definite task. In addition, a function in
SQL Server accepts input parameters and returns the desired
output. More importantly, SQL functions are not used to insert,
update, or delete data from a database. Every function in SQL
Server has a specific name and does not begin with special
symbols, such as $, #, or @. SQL Server has two distinct kinds
of SQL Server: predefined and user-defined.

• Predefined Functions:

Functions defined by SQL Server are called pre-defined


functions. Aggregate functions and scalar functions are two
different kinds of predefined functions in SQL Server.
Aggregate functions are min(), sum(), count(), max(), and avg(),
whereas scalar functions are round(), ucase(), lcase(), format(),
mid(), len(), and now().

• User-defined Functions:

A block of SQL statements written by a programmer or


developer to accomplish a particular task is called a user-
defined function.

pg. 12 HIMANSHU KUMAR (LINKEDIN)


PART-1

20. Explain Aggregate functions in


SQL Server.
Answer: Aggregate functions in SQL Server group values from
multiple rows of a table under specific criteria and return a
single value. There are five aggregate functions in SQL Server,
as given below:
• sum():

It takes all values from different rows and returns their sum value.

• max():

This function accepts values from multiple tuples, compares them, and
returns the maximum value.

• min():

This function accepts values from multiple tuples, compares them, and
returns the minimum value.

• count():

This function returns the total number of rows or records present in a


table.

• avg():

This function accepts values from multiple tuples and returns an


average of all values.

HIMANSHU KUMAR(LINKEDIN)
https://www.linkedin.com/in/himanshukumarmahuri
JOIN TELEGRAM TO DOWNLOAD- https://t.me/placement_preparations

pg. 13 HIMANSHU KUMAR (LINKEDIN)

You might also like