You are on page 1of 5

31.

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:


1
2
3
4

CREATE PROCEDURE PROCEDURE_NAME


AS
SQL_QUERY (GIVE YOUR OFTEN USED QUERY HERE)
GO;

You can execute the Stored Proc by using the command Exec Procedure_Name;
32. 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.
33. 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.
34. 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.
35. 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.
36. 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.
37. 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.
38. 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.
39. 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.
40. How to find nth highest salary in SQL Server without using a subquery

This is one of the common SQL Interview questions that have been asked in several
Job interviews.

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.
41. How to install SQL Server in Windows 10

Click on the below SQL Server official release link:


https://www.microsoft.com/en-in/sql-server/sql-server-downloads
Click on the search icon and type in – SQL Server 2012 download
Click on the result link to download and save SQL Server 2012.
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.
Click on the Download Now button.
Save the .exe file on your system. Right-click on the .exe file and click on
Open.
Click on ‘Yes’ to allow the changes to be made on your system and have SQL
Server Installed

42. 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:
1
2
3

SELECT COL1, COL2


INTO TEMPTABLE1
FROM ORIGTABLE;

Temporary tables do not occupy any physical memory and can be used to retrieve data
faster.
43. What is schema in SQL Server?

This is one of the common SQL Interview questions that have been asked in several
Job interviews.

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 the Star
schema and Snowflake schema. Star schema is the one that has the entities
represented in a star shape, and the snowflake schema has its entities represented
in a snowflake shape.

Schemas form the basis of any database design.


Learn In-Demand Skills for free on GL Academy
This brings us to the end of the SQL Interview questions. Glad to see you are now
better equipped to face an interview.

Now lets have a look at top common interview questions here.


PostgreSQL Interview Questions
1. What is PostgreSQL?

PostgreSQL is one of the most widely and popularly used languages for Object-
Relational Database Management systems. It is mainly used for large web
applications. It is an open-source, object-oriented, -relational database system.
It is extremely powerful and enables users to extend any system without problem. It
extends and uses the SQL language in combination with various features for safely
scaling and storage of intricate data workloads.
2. List different datatypes of PostgreSQL?

Listed below are some of the new data types in PostgreSQL

UUID
Numeric types
Boolean
Character types
Temporal types
Geometric primitives
Arbitrary precision numeric
XML
Arrays etc

3. What are the Indices of PostgreSQL?

Indices in PostgreSQL allow the database server to find and retrieve specific rows
in a given structure. Examples are B-tree, hash, GiST, SP-GiST, GIN and BRIN.
Users can also define their indices in PostgreSQL. However, indices add overhead to
the data manipulation operations and are seldom used
4. What are tokens in PostgreSQL?

Tokens in PostgreSQL act as the building blocks of a source code. They are composed
of various special character symbols. Commands are composed of a series of tokens
and terminated by a semicolon(“;”). These can be a constant, quoted identifier,
other identifiers, keyword or a constant. Tokens are usually separated by
whitespaces.
5. How to create a database in PostgreSQL?

Databases can be created using 2 methods

First is the CREATE DATABASE SQL Command

We can create the database by using the syntax:- CREATE DATABASE <dbname>;

The second is by using the createdb command

We can create the database by using the syntax:- createdb [option…] <dbname>
[description]

Various options can be taken by the createDB command based on the use case.
6. How to create a table in PostgreSQL?

You can create a new table by specifying the table name, along with all column
names and their types:
CREATE TABLE [IF NOT EXISTS] table_name (

column1 datatype(length) column_contraint,

column2 datatype(length) column_contraint,

You might also like