List of 90 Sql Server Interview Question and Answer

List of 90 SQL Server Interview Questions and Answers





Q #1) What is SQL?


Answer: Structured Query Language SQL is a database tool that is used to create and access the database to support software applications.


Q #2) What are tables in SQL?


Answer: The table is a collection of records and information in a single view.


Q #3) What are the different types of statements supported by SQL?


Answer:


statements supported by SQL


There are 3 types of SQL statements:


a) DDL (Data Definition Language): It is used to define the database structure such as tables. It includes three statements such as CREATE, ALTER, and DROP.


Some of the DDL Commands are listed below:


CREATE: It is used for creating the table.


CREATE TABLE table_name

column_name1 data_type(size),

column_name2 data_type(size),

column_name3 data_type(size),

ALTER: The ALTER table is used for modifying the existing table object in the database.


ALTER TABLE table_name

 ADD column_name datatype

OR


ALTER TABLE table_name

DROP COLUMN column_name


b) DML (Data Manipulation Language): These statements are used to manipulate the data in records. Commonly used DML statements are INSERT, UPDATE, and DELETE.


The SELECT statement is used as a partial DML statement, used to select all or relevant records in the table.


c) DCL (Data Control Language): These statements are used to set privileges such as GRANT and REVOKE database access permission to the specific user.


Q #4) How do we use the DISTINCT statement? What is its use?


Answer: The DISTINCT statement is used with the SELECT statement. If the record contains duplicate values then the DISTINCT statement is used to select different values among duplicate records.


Syntax:


SELECT DISTINCT column_name(s)

 FROM table_name;


Q #5) What are different Clauses used in SQL?


Answer:


Clauses used in SQL


WHERE Clause: This clause is used to define the condition, extract and display only those records which fulfill the given condition.


Syntax:


SELECT column_name(s)

 FROM table_name

 WHERE condition;


GROUP BY Clause: It is used with a SELECT statement to group the result of the executed query using the value specified in it. It matches the value with the column name in tables and groups the end result accordingly.


Syntax:


SELECT column_name(s)

 FROM table_name

 GROUP BY column_name;


HAVING clause: This clause is used in association with the GROUP BY clause. It is applied to each group of results or the entire result as a single group. It is much similar to the WHERE clause but the only difference is you cannot use it without the GROUP BY clause


Syntax:


SELECT column_name(s)

 FROM table_name

 GROUP BY column_name

 HAVING condition;


ORDER BY clause: This clause is used to define the order of the query output either in ascending (ASC) or descending (DESC). Ascending (ASC) is set as the default one but descending (DESC) is set explicitly.


Syntax:


SELECT column_name(s)

 FROM table_name

 WHERE condition

 ORDER BY column_name ASC|DESC;


USING clause: USING clause comes in use while working with SQL JOIN. It is used to check equality based on columns when tables are joined. It can be used instead of the ON clause in JOIN.


Syntax:


SELECT column_name(s)

 FROM table_name

 JOIN table_name

 USING (column_name);

Step-by-Step: SQL Server Download and Installation Process

 For use with MS SQL server, Microsoft offers two specialized free SQL download editions:
1.     Developer – Developer - It has all the features that MS SQL Server provides, but we are unable to use it in production. It is the best place to begin from the standpoint of learning.
2.     Express: This version of the SQL server is also available for free download, but it has fewer functionality and no business intelligence applications. For installation, we'll use the MS SQL server download Developer edition.
Step 2) Select "Download Now"
Download SQL Server Setup
Our SQL server installation will be configured as 'SQLServer2017-SSEI-Dev.exe'.
Download SQL Server Setup
Installing SQL Server: Steps
the steps to install SQL in Windows 10 are as follows:
Step 1) Open the.exe file in step one.
Click "SQLServer2017-SSEI-Dev.exe" twice. There will be three options on the screen below: Basic, Custom, and Download files.
Install SQL Server
Step 2) Select the version
The 'Basic' option should be selected if you want to use the basic version, which has all the default configurations needed to learn MS SQL.
Install SQL Server
Step 3) Accept the conditions
The screen titled "Microsoft Server License Terms" will appear. Click "Accept" after reading the License Terms.
Install SQL Server
Step 4) Select the site
The 'SQL server install location' window will show up below.
1.      Microsoft SQL Server's default location is “C> Program Files”.
2.     By selecting Browse, we can also choose to alter the installation place.
3.     To launch the SQL installation for Windows 10 after choosing the location, click the 'Install' option.
Install SQL Server
The 'Downloading install package' progress screen will be below.Install SQL Server
displayed. As soon as the SQL software download is finished, wait.Install SQL Server
Install SQL Server
Installation progress is displayed below the screen.Install SQL Server
Step 5) Complete the setup procedure.
Install SQL Server
We can "Close" this window because this configuration is self-sufficient for moving forward with understanding the SQL server.
However, the label and button are summarized below:
1.     Name of the instance: By default, this is identified as MSSQLSERVER.
2.     Now connect: This will open a different command line window so you can test your connection to the newly installed software. The system will automatically execute the "select @@Version" command to make sure we can successfully connect to the new MSSQLSERVER instance.Install SQL Server
3. Individualise: Doing so will launch the SQL Installation with the ability to add features that are not already included in the BASIC installation and to further modify the system.
4. Install SSMS: This is the IDE that will direct us to the Microsoft SSMS download page. In our SSMS tutorial, we will go through SSMS in depth.
5. Close: This will bring this window to a close. The user is now prepared to install the SSMS IDE as described in the SSMS tutorial.
x
x

Update in SQL Server

How to update in sql Server?

The update statement is used to update existing records in a table.

Syntax:-

UPDATE Table_name SET Column1=value1,column2=value2 WHERE someColumn=somevalue.

Example:-

UPDATE Employee SET Frst_name='Ram',Addres='Kolkata' WHERE EmpID ='1'

Note:-

If we cannot include the WHERE clause then all records will update.

Insert into Table

How to insert data in the sql server?

->Insert into statement is used to insert a new row in a table.

->It will write in two ways.

1)First Way Syntax:-

INSERT INTO Table_Name
VALUES(value1,value2,value3,...)

Example:-

INSERT INTO Table_Name
VALUES(1,'Er Vijay','Narayan Mishra','Kolkata')

2)Second Way Syntax:-

INSERT INTO Table_Name(column1,column2,column3,..)

VALUES(value1,value2,value3,...)

Example:-

INSERT INTO Table_Name(ID,First_name,Last_name)

VALUES(1,'Er Vijay','Narayan Mishra')

Unique Constraint in SQL Server

What are Unique constraints in SQL Server?

Unique constraints uniquely identifies each records in a database


Syntax

CREATE TABLE Table_name(
    column1 Datatype1 NOT NULL,
    column2 Datatype2  NOT NULL,

    column3 Datatype3  NOT NULL,
    column4 Datatype4 ,

UNIQUE(columnname));
Example

CREATE TABLE Table_name(
    EmpID Int NOT NULL,
    Emp_Name Varchar(200)  NOT NULL,

    Address Varchar(200)  NOT NULL,
    Age int,

UNIQUE(EmpId));

Not Null Constraint

What is Not Null constraints?

->In Sql Server by default column holds NULL values but when we add NOT NULL constraints It cannot hold NULL values.

->Not Null constraints enforce a column to not accept NULL values.

Syntax

CREATE TABLE Table_name(
    column1 Datatype1 NOT NULL,
    column2 Datatype2  NOT NULL,

    column3 Datatype3  NOT NULL,
    column4 Datatype4 
);


Example

CREATE TABLE Table_name(
    EmpID Int NOT NULL,
    Emp_Name Varchar(200)  NOT NULL,

    Address Varchar(200)  NOT NULL,
    Age int
);