1. What is SQL Server

SQL server has stayed on top as one of the most popular database management products ever since its first release in 1989 by Microsoft Corporation. The product is used across industries to store and process large volumes of data. It was primarily built to store and process data that is built on a relational model of data. 

SQL Server is widely used for data analysis and also scaling up of data. SQL Server can be used in conjunction with Big Data tools such as Hadoop. 

SQL Server can be used to process data from various data sources such as Excel, Table, .Net Framework application, etc.

  1. How to install SQL Server
    1. Click on the below SQL Server official release link to access the latest version: https://www.microsoft.com/en-in/sql-server/sql-server-downloads

    2.Select the type of SQL Server edition that you want to install. SQL Server can be used on a Cloud Platform or as an open-source edition(Express or Developer) in your local computer system. 

    3.Click on the Download Now button.

    4.Save the .exe file on your system. Right-click on the .exe file and click on Open.

    5.Click on ‘Yes’ to allow the changes to be made on your system and have SQL Server Installed.

    6.Once the installation is complete, restart your system, if required, and launch the SQL Server Management Studio application from the START menu.
  1. How to create a stored procedure in SQL Server

A Stored Procedure is nothing but a frequently used SQL query. Queries such as a SELECT query, which would often be used to retrieve a set of information many times within a database, can be saved as a Stored Procedure. The Stored Procedure, when called, executes the SQL query save within the Stored Procedure.

Syntax to create a Stored Proc:

<!-- wp:paragraph -->
<p><strong>CREATE PROCEDURE </strong><strong><em>PROCEDURE_NAME</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>AS</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong><em>SQL_QUERY (GIVE YOUR OFTEN USED QUERY HERE)</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>GO;</strong></p>
<!-- /wp:paragraph -->

Stored procedures can be user-defined or built-in. Various parameters can be passed onto a Stored Procedure.

  1. How to install SQL Server 2008
    1.Click on the below SQL Server official release link: https://www.microsoft.com/en-in/sql-server/sql-server-downloads
  1. Click on the search icon and type in – SQL Server 2008 download
  2. Click on the result link to download and save SQL Server 2008.
  3. Select the type of the SQL Server edition that you want to install. SQL Server can be used on a Cloud Platform or as an open-source edition(Express or Developer) in your local computer system. 
  1. Click on the Download Now button.
  2. Save the .exe file on your system. Right-click on the .exe file and click on Open.
  3. Click on ‘Yes’ to allow the changes to be made on your system and have SQL Server installed.
  4. Once the installation is complete, restart your system, if required, and launch the SQL Server Management Studio application.
  1. How to install SQL Server 2017
    1.Click on the below SQL Server official release link: https://www.microsoft.com/en-in/sql-server/sql-server-downloads
  1. Click on the search icon and type in – SQL Server 2017 download
  2. Click on the result link to download and save SQL Server 2017.
  3. Select the type of the SQL Server edition that you want to install. SQL Server can be used on a 

Cloud Platform or as an open-source edition(Express or Developer) in your local computer system. 

  1. Click on the Download Now button.
  2. Save the .exe file on your system. Right-click on the .exe file and click on Open.
  3. Click on ‘Yes’ to allow the changes to be made on your system and have SQL Server installed.
  1. Once the installation is complete, restart your system, if required, and launch the SQL Server Management Studio application from the START menu.
  1. How to restore the database in SQL Server

Launch the SQL Server Management Studio application and from the Object Explorer window pane, right-click on Databases and click on Restore. This would automatically restore the database.

  1. How to install SQL Server 2014

    1.Click on the below SQL Server official release link: https://www.microsoft.com/en-in/sql-server/sql-server-downloads
  1. Click on the search icon and type in – SQL Server 2014 download
  2. Click on the result link to download and save SQL Server 2014.
  3. Select the type of the SQL Server edition that you want to install. SQL Server can be used on a Cloud Platform or as an open-source edition(Express or Developer) in your local computer system. 
  1. Click on the Download Now button.
  2. Save the .exe file on your system. Right-click on the .exe file and click on Open.
  3. Click on ‘Yes’ to allow the changes to be made on your system and have SQL Server Installed.
  1. Once the installation is complete, restart your system, if required, and launch the SQL Server Management Studio application from the START menu.
  1. How to get the connection string from SQL Server

Launch the SQL Server Management Studio. Go to the Database for which you require the Connection string. Right-click on the database and click on Properties. In the Properties window that is displayed, you can view the Connection String property.

Connection strings help connect databases to another staging database or any external source of data.

  1. How to install SQL Server 2012
    Click on the below SQL Server official release link: https://www.microsoft.com/en-in/sql-server/sql-server-downloads
  1. Click on the search icon and type in – SQL Server 2012 download
  2. Click on the result link to download and save SQL Server 2012.
  3. Select the type of the SQL Server edition that you want to install. SQL Server can be used on a 

Cloud Platform or as an open-source edition(Express or Developer) in your local computer system. 

  1. Click on the Download Now button.
  2. Save the .exe file on your system. Right-click on the .exe file and click on Open.
  3. Click on ‘Yes’ to allow the changes to be made on your system and have SQL Server

Installed.

  1. Once the installation is complete, restart your system, if required, and launch the SQL Server Management Studio application from the START menu.
  1. What is cte in SQL Server?

CTEs are Common Table Expressions that are used to create temporary result tables from which data can be retrieved/ used. The standard syntax for a CTE with a SELECT statement is:

WITH RESULT AS 

(SELECT COL1, COL2, COL3

FROM EMPLOYEE)

SELECT COL1, COL2 FROM RESULT

CTEs can be used with Insert, Update or Delete statements as well.

Few examples of CTEs are given below:

Query to find the 10 highest salaries.

with result as 

(select distinct salary, dense_rank() over (order by salary desc) as salary rank from employees)

select result. salary from result where the result.salaryrank = 10 

Query to find the 2nd highest salary

with the result as 

(select distinct salary, dense_rank() over (order by salary desc) as salaryrank from employees)

select result. salary from result where the result.salaryrank = 2

In this way, CTEs can be used to find the nth highest salary within an organisation.

  1. How to change SQL Server password

Launch your SQL Server Management Studio. Click on the Database connection for which you want to change the login password. Click on Security from the options that get displayed. 

Click on Logins and open your database connection. Type in the new password for login and click on ‘OK’ to apply the changes. 

  1. How to delete duplicate records in SQL Server

Select the duplicate records in a table HAVING COUNT(*)>1 

Add a delete statement to delete the duplicate records.

Sample Query to find the duplicate records in a table-

(SELECT COL1, COUNT(*) AS DUPLICATE

FROM EMPLOYEE

GROUP BY COL1

HAVING COUNT(*) > 1)

  1. How to uninstall SQL Server

In Windows 10, go to the START menu and locate the SQL Server.

Right-click and select uninstall to uninstall the application.

  1. How to check SQL Server version

You can run the below query to view the current version of SQL Server that you are using.

SELECT @@version;

  1. How to rename column name in SQL Server

From the Object Explorer window pane, go to the table where the column is present and choose Design. Under the Column Name, select the name you want to rename and enter the new name. Go to the File menu and click Save. 

  1. What is the stored procedure in SQL Server?

A Stored Procedure is nothing but a frequently used SQL query. Queries such as a SELECT query, which would often be used to retrieve a set of information many times within a database, can be saved as a Stored Procedure. The Stored Procedure, when called, executes the SQL query save within the Stored Procedure.

Syntax to create a Stored Proc:

<!-- wp:paragraph -->
<p><strong>CREATE PROCEDURE </strong><strong><em>PROCEDURE_NAME</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>AS</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong><em>SQL_QUERY (GIVE YOUR OFTEN USED QUERY HERE)</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>GO;</strong></p>
<!-- /wp:paragraph -->

You can execute the Stored Proc by using the command Exec Procedure_Name;

  1. How to create a database in SQL Server

After installing the required version of SQL Server, it is easy to create new databases and maintain them. 

  1. Launch the SQL Server Management Studio
  2. In the Object Explorer window pane, right-click on Databases and select ‘New Database’
  3. Enter the Database Name and click on ‘Ok’.
  4. Voila! Your new database is ready for use.
  1. What is an index in SQL Server?

Indexes are database objects which help in retrieving records quickly and more efficiently. Column indexes can be created on both Tables and Views. By declaring a Column as an index within a table/ view, the user can access those records quickly by executing the index. Indexes with more than one column are called Clustered indexes.

Syntax:

CREATE INDEX INDEX_NAME 

ON TABLE_NAME(COL1, COL2);

The syntax to drop an Index is DROP INDEX INDEX_NAME;

Indexes are known to improve the efficiency of SQL Select queries. 

  1. How to create the table in SQL Server

Tables are the fundamental storage objects within a database. A table is usually made up of 

Rows and Columns. The below syntax can be used to create a new table with 3 columns.

CREATE TABLE TABLE_NAME(

COLUMN1 DATATYPE, 

COLUMN2 DATATYPE, 

COLUMN3 DATATYPE

);

Alternatively, you can right-click on Table in the Object Explorer window pane and select ‘New -> Table’.

You can also define the type of Primary/ Foreign/ Check constraint when creating a table.

  1. How to connect to SQL Server
  1. Launch the SQL Server Management Studio from the START menu.
  2. In the dialog box shown below, select the Server Type as Database Engine and Server Name as the name of your laptop/ desktop system.
  3. Select the appropriate Authentication type and click on the Connect button.
  4. A secure connection would be established, and the list of the available Databases will be loaded in the Object Explorer window pane.
  1. How to delete duplicate rows in SQL Server

Select the duplicate records in a table HAVING COUNT(*)>1 

Add a delete statement to delete the duplicate records.

Sample Query to find the duplicate records in a table-

(SELECT COL1, COUNT(*) AS DUPLICATE

FROM EMPLOYEE

GROUP BY COL1

HAVING COUNT(*) > 1);

  1. How to download SQL Server

The Express and Developer versions (open-source versions) of the latest SQL Server release can be downloaded from the official Microsoft website. The link is given below for reference.
https://www.microsoft.com/en-in/sql-server/sql-server-downloads

  1. How to connect SQL Server management studio to the local database
  1. Launch the SQL Server Management Studio from the START menu.
  2. In the dialog box shown below, select the Server Type as Database Engine and Server Name as the name of your laptop/ desktop system and click on the Connect button.
  3. Select the Authentication as ‘Windows Authentication.
  4. A secure connection would be established, and the list of the available Databases will be loaded in the Object Explorer window pane.
  1. How to change column name in SQL Server

From the Object Explorer window pane, go to the table in which the column is present and choose Design. Under the Column Name, select the name you want to rename and enter the new name. Go to the File menu and click Save.

  1. How to download SQL Server 2014
  1. Both the Express and Developer versions (free editions) of SQL Server can be downloaded from the official Microsoft website. The link is given below for reference.
  2. Click on the link below : https://www.microsoft.com/en-in/sql-server/sql-server-downloads
  1. Click on the search icon and type in – SQL Server 2014 download
  2. Click on the result link to download and save SQL Server 2014.
  1. How to uninstall SQL Server 2014

From the START menu, type SQL Server. Right-click on the app and select uninstall to uninstall the application from your system. Restart the system, if required, for the changes to get affected. 

  1. How to find server name in SQL Server

Run the query SELECT @@version; to find the version and name of the SQL Server you are using. 

  1. How to start SQL Server

Launch the SQL Server Management Studio from the START menu. Login using Windows Authentication. In the Object Explorer window pane, you can view the list of databases and corresponding objects. 

  1. What is the case when in SQL Server?

Case When statements in SQL are used to run through many conditions and to return a value when one such condition is met. If none of the conditions is met in the When statements, then the value mentioned in the Else statement is returned. 

Syntax:

<!-- wp:paragraph -->
<p><strong><em>CASE</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong><em>WHEN CONDITION1 THEN RESULT1</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong><em>WHEN CONDITION2 THEN RESULT2</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong><em>ELSE</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong><em>RESULT</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong><em>END;</em></strong></p>
<!-- /wp:paragraph -->


Sample query:

HOW MANY HEAD OFFICES/ BRANCHES ARE THERE IN CANADA

select 
sum ( 
case 
when region_id >=  5 AND region_id <= 7 then  
1
else 
0
end ) as Canada
from company_regions;
Nested CASE statement:
SELECT
SUM (
CASE
WHEN rental_rate = 0.99 THEN
1
ELSE
0
END
) AS “Mass”,
SUM (
CASE
WHEN rental_rate = 2.99 THEN
1
ELSE
0
END
) AS “Economic”,
SUM (
CASE
WHEN rental_rate = 4.99 THEN
1
ELSE
0
END
) AS ” Luxury”
FROM
film;

  1. How to install SQL Server management studio

Launch Google and in the Search toolbar, type in SQL Server Management Studio’ download. 

Go to the routed website and click on the link to download. Once the download is complete, open the .exe file to install the content of the file. Once the installation is complete, refresh or restart the system, as required.

Alternatively, once SQL Server is installed and launched, it will prompt the user with an option to launch SQ Server Management Studio. 

  1. How to write a stored procedure in SQL Server

A Stored Procedure is nothing but a frequently used SQL query. Queries such as a SELECT query, which would often be used to retrieve a set of information many times within a database, can be saved as a Stored Procedure. The Stored Procedure, when called, executes the SQL query save within the Stored Procedure.

Syntax to create a Stored Proc:

<!-- wp:paragraph -->
<p><strong>CREATE PROCEDURE </strong><strong><em>PROCEDURE_NAME</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>AS</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong><em>SQL_QUERY (GIVE YOUR OFTEN USED QUERY HERE)</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>GO;</strong></p>
<!-- /wp:paragraph -->

You can execute the Stored Proc by using the command Exec Procedure_Name;

  1. What is a trigger in SQL Server?

Triggers in SQL Server are automatic functions that get executed AFTER or BEFORE an event occurs. 

For example: Trigger to update the employee’s salary to $40000 AFTER getting a promotion to job level band D1. It is also referred to as a type of Stored Procedure. The type of trigger as AFTER or BEFORE is defined in the syntax of the trigger itself.

  1. How to open SQL Server

Launch the SQL Server Management Studio from the START menu. Login using Windows Authentication. In the Object Explorer window pane, you can view the list of databases and corresponding objects. 

  1. How to connect SQL Server

The most common way of connecting to a SQL Server is using Windows Authentication. 

Make sure to select the Server Name as the desktop or laptop system name. 

  1. What is replication in SQL Server?

Replication of a database node is the most common way to prevent the complete loss of any data. When a database is replicated/ taken a copy of, it can be used across databases for data reuse and synchronization. Apart from the primary motive of data backup, replicated data is also used for data analysis in Big Data projects. 

  1. How to open SQL Server configuration manager

Click on the START menu and select All Programs. Select Microsoft SQL Server, select Configuration Tools, and then select SQL Server Configuration tools. In that, select the SQL Server Configuration Manager.

  1. What is a collation in SQL Server?

Collation refers to a set of pre-defined rules on SQL Server, which define the encoding rules of character data both at a database and server level. Collation rules can be used on Metadata as well.

  1. How to use SQL Server

SQL Server is used to retrieve and process various data that is built on a relational model.

Some of the common actions that can be taken on the data are CREATE, DELETE, INSERT, UPDATE, SELECT, REVOKE, etc.

SQL Server can also be used to import and export data from different data sources. SQL Server can also be connected to various other databases/ .Net framework using Connection Strings.

SQL Server can also be used in conjunction with Big Data tools like Hadoop. 

  1. What is a function in SQL Server?

Functions are pre-written codes that return a value and which help the user achieve a particular task concerning viewing, manipulating, and processing data.

Examples of few functions are:

AGGREGATE FUNCTIONS:

MIN()- Returns the minimum value

MAX()- Retuns the maximum value

AVG()- Returns the average value

COUNT()

STRING FUNCTIONS:

COALESCE()

CAST()

CONCAT()

SUBSTRING()

DATE FUNCTIONS:

GETDATE()

DATEADD()

DATEDIFF()

There are many types of functions such as Aggregate Functions, Date Functions, String Functions, Mathematical functions, etc.

  1. How to find nth highest salary in SQL Server without using a subquery

Query to find the 10 highest salary. For up-gradation of the b10 band.

with result as 

(select distinct salary, dense_rank() over (order by salary desc) as salaryrank from employees)

select result.salary from result where result.salaryrank = 10

Query to find the 2nd highest salary

with the result as 

(select distinct salary, dense_rank() over (order by salary desc) as salaryrank from employees)

select result.salary from result where result.salaryrank = 2

In this way, by replacing the salaryrank value, we can find the nth highest salary in any organisation.

  1. How to install SQL Server in Windows 10

    1. Click on the below SQL Server official release link: https://www.microsoft.com/en-in/sql-server/sql-server-downloads
  1. Click on the search icon and type in – SQL Server 2012 download
  2. Click on the result link to download and save SQL Server 2012.
  3. Select the type of the SQL Server edition that you want to install. SQL Server can be used on a 

Cloud Platform or as an open-source edition(Express or Developer) in your local computer system. 

  1. Click on the Download Now button.
  2. Save the .exe file on your system. Right-click on the .exe file and click on Open.
  3. Click on ‘Yes’ to allow the changes to be made on your system and have SQL Server

Installed.

  1. How to create a temp table in SQL Server

Temporary tables can be used to retain the structure and a subset of data from the original table from which they were derived. 

Syntax:

<!-- wp:paragraph -->
<p><strong>SELECT COL1, COL2 </strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>INTO TEMPTABLE1</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>FROM ORIGTABLE;</strong></p>
<!-- /wp:paragraph -->

Temporary tables do not occupy any physical memory and can be used to retrieve data faster.

  1. What is schema in SQL Server?

A schema is a logical visual representation of the database. It establishes and defines the relationship between the various entities of a database. It describes the type of Constraints that are applied to a database. It also explains the data types that are used. It can be used on Tables and Views as well. 

There are different types of schema. Some of the most popular ones are Star schema and Snowflake schema. Star schema is the one that has the entities represented in a star shape, and snowflake schema has its entities represented in a snowflake shape.

Schemas form the basis of any database design. 

0

LEAVE A REPLY

Please enter your comment!
Please enter your name here

two × one =