0% found this document useful (0 votes)
5 views12 pages

Basic

Uploaded by

beroye1833
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
5 views12 pages

Basic

Uploaded by

beroye1833
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 12

SQL

BASIC

1. What are the query languages used by Microso SQL Server?


SQL Server is a ‘rela onal database management system’ and it is the product of Microso
developed for Enterprise environment. SQL Server uses two query languages which are as
follows:

 Transact-SQL (T-SQL)
 ANSI-SQL
2. Describe different components in SQL Server Architecture?
The different components are as follows:
 Database Engine: It is the core service for storing, processing and securing data
 Analysis Services: It is an online analy cal data engine used in decision support and
BI solu ons
 Repor ng Services: It includes a complete set of tools to create, manage and deliver
reports
 Integra on Services: It is a pla orm for building enterprise-level data integra on and
data transforma ons solu ons
3. Describe different edi ons of SQL Server?
Microso has got different edi ons of SQL Server targe ng different users.
 Enterprise
 High end, all inclusive product
 Support for Always-on availability
 Advanced audi ng
 Standard
 Support for basic BI and repor ng features
 Does not support advanced features such as data warehousing
 BI
 Includes all standard and enterprise edi on features
 No support for advanced tuning
 Express

 Includes new Local DB feature for lightweight deployments


 Free edi on
4. What is the use of database engine in SQL Server?
Database engine is core service used for crea ng rela onal databases for OLTP or OLAP. It
provides controlled access and rapid transac on processing to meet the requirements of the
most demanding data consuming applica ons within your enterprise. It also provides rich
support for sustaining high availability.
5. What is the purpose of SQL Server Agent in SQL Server?
SQL Server Agent is a Microso Windows Service that automates administra ve tasks. It
runs jobs, monitors SQL Server and process alerts. Jobs can be scheduled using SQL Server
Agent. SQL Server Agent jobs can be created and scheduled under object explorer.
6. What are the different tools used for database development and maintenance?
Different tools used are as follows:
adver sement
 SQL Server Management Studio
 SQL Server Configura on Manager
 SQL Server Data Tools
 SQL Profiler and DTA
7. Explain different system databases in SQL Server?
Different databases are as follows:
 master: records all system level informa on

 msdb: used by SQL Server agent to schedule jobs


 model: used as template for all databases created on instance of SQL Server.
 resource: read only database that contain system objects
 tempdb: is a workspace for holding temporary objects
8. Explain data storage in SQL Server?
SQL Server data is organized in to files. When a database is created, two types of files are
created:
 Data files (.mdf) – It is the main repository for the database
 Log files (.ldf) – These logs are used for data recovery
9. Explain different types of instance in SQL Server?

SQL Server supports mul ple instances of SQL Server concurrently running on same
computer.
Default: It is solely iden fied by computer name.By default, components try to connect to
this instance
Named: It is iden fied by instance name specified during installa on of the instance
10. What are the different database objects in SQL Server?
Some of the Database objects are as follows:
 Scalar func ons
 System tables
 System stored procedures
 User defined tables

 User defined data type


 Inline table func ons
11. Explain different data types in SQL Server?
Different category of data types with example are as follows:
 Exact numerics: INT, MONEY
 Approximate numerics: FLOAT, REAL
 Date and me: DATETIME, SMALLDATETIME, DATE
 Character strings: CHAR, VARCHAR, TEXT
 Binary strings: BINARY, VAR BINARY, IMAGE
12. Explain the concept of variables in SQL Server?

There are two types of variables in SQL Server:


 Global
 Always prefixed with ‘@@’ sign.
 are predefined and maintained by system
 Local
 Must be prefixed with ‘@’ sign
 User defined
 Ini alized to null when created
 Confined to batch
13. What are different foreign key constraints in SQL Server?

Different foreign key constraints are as follows:


 ON DELETE SET NULL: A foreign key with “set null on delete” means that if a record
in the parent table is deleted, then the corresponding records in the child table will
have the foreign key fields set to NULL
 ON DELETE CASCADE: A foreign key with cascade delete means that if a record in the
parent table is deleted, then the corresponding records in the child table will
automa cally be deleted.
 ON DELETE SET DEFAULT: Specifies that if an a empt is made to delete a row with a
key referenced by foreign keys in exis ng rows in other tables, all the values that
make up the foreign key in the rows that are referenced are set to their default value.
14. What do you mean by bulk insert in SQL Server?
BULK INSERT is used to import data from a data file in to a table or view. The format of the
imported data can be specified, based on how that data is stored in the file. Using the BULK
INSERT statement we can insert bulk data into the database directly from a CSV file.
15. Do we have natural join in SQL Server?
Natural join is a type of equi-join which occurs implicitly by comparing all the same names
columns in both tables. The join result have only one column for each pair of equally named
columns. Natural join is not supported by current SQL Server version.
16. What is the purpose of TOP clause in SQL Server?
TOP clause limits the rows returned in a query result set to a specified number of rows or
percentage of rows. When TOP is used in conjunc on with the ORDER BY clause, the result
set is limited to the first N number of ordered rows; otherwise, it returns the first N number
of rows in an undefined order.
17. Why do we need common table expression in SQL Server?
A CTE can be used to:
 Create a recursive query
 Subs tute for a view when the general use of a view is not required
 Enable grouping by a column that is derived from a scalar subselect
 Reference the resul ng table mul ple mes in the same statement
18. What are the different ranking func ons in SQL Server?
Ranking func ons return a ranking value for each row in a par on. Transact-SQL provides
the following ranking func ons:
 RANK
 DENSE_RANK

 NTILE
 ROW_NUMBER
19. What are the different batch programming control flow statements?
Procedural features are included in T-SQL for easier processing of data.Control flow
statements supported are as follows:
 IF ELSE
 While
 CASE
 Goto
20. What is user defined func on in SQL Server and enlist it’ types?
User defined func on is a T-SQL rou ne that returns a value. It can be invoked by query. It
can be executed like stored procedure. Types of user defined func ons are as follows:
 Scalar
 Inline table valued func on
 Mul -statement table valued func on
21. Explain usage of triggers in SQL Server?
A trigger is a special kind of stored procedure that automa cally executes when an event
occurs in the database server. DML triggers execute when a user tries to modify data
through a data manipula on language (DML) event. DDL triggers execute in response to a
variety of data defini on language (DDL) events. SQL Server allows for crea ng mul ple
triggers for any specific statement.
22. Explain different types of trigger in SQL Server?
There are three type of Triggers
 DML Triggers
 Instead of Trigger: Instead of trigger are fired in place of the triggering ac on
such as an insert, update, or delete
 A er Trigger: A er trigger execute following the triggering ac on, such as an
insert, update, or delete.
 DDL Triggers: This type of trigger is fired against DDL statements like Drop Table,
Create Table or Alter Table. DDL Triggers are always a er Triggers
 Logon trigger: This type of trigger is fired against a LOGON event before a user
session is established to the SQL Server
23. Explain excep on handling in SQL Server?
TRY…CATCH implements error handling for Transact-SQL .A group of Transact-SQL
statements can be enclosed in a TRY block. If an error occurs in the TRY block, control is
passed to another group of statements that is enclosed in a CATCH block.
24. What are different transac on control statements?
The three different transac on control statements are:
 BEGIN: Alerts SQL Server that transac on is beginning
 Rollback: Undoes the changes to the named savepoint or the beginning of
transac on
 Commit: End the transac on and saves changes to the database
25. Which resources can be locked by database engine?

The following are the resources that the database engine can lock:
 RID
 Key
 Page
 Event
 Table
 File
 Metadata
 Applica on
 Database

ADVANCED

26. Explain advantages of mul ple instances in SQL Server?


Advantages are as follows:
 A machine having mul ple instance can support many organiza ons
 A single organiza on can host ten server applica on on a single machine
 One machine can be used for repor ng, reproducing problems and bug fixing
27. What is the purpose of Output Clause in SQL Server?

Output clause returns informa on from each row affected by following statements:
 UPDATE
 DELETE
 INSERT
 MERGE
These results can be returned to the processing applica on to be used as confirma on
message.
28. Explain spa al types in SQL Server?
The geography spa al data type, geography, is implemented as a .NET common language
run me (CLR) data type in SQL Server. This type represents data in a round-earth coordinate
system. The SQL Server geography data type stores ellipsoidal (round-earth) data, such as
GPS la tude and longitude coordinates.
The planar spa al data type, geometry, is implemented as a common language run me
(CLR) data type in SQL Server. This type represents data in a Euclidean (flat) coordinate
system.
29. Explain advantages and drawbacks of FILESTREAM data type?
Advantages
 Taken care by SQL Server
 Reliable
 Storage capacity is limited to disk volumes
Drawbacks

 Database mirroring and snapshot are not supported


 Cannot be used as table valued parameter
 Supported isola on level is read commi ed
30. What is the difference between inline and mul -statement table valued func on?
Inline Table-Valued Func ons returns a resultset, as opposed to a single scalar value. Mul -
statement Table-Valued Func on also returns a resultset, like the Inline variety UDF, but with
a much more powerful result. When an inline table-valued func on is used as part of an
outer query, the query processor expands the UDF defini on and generates an execu on
plan that accesses the underlying objects, using the indexes on these objects. For a mul -
statement table valued func on, an execu on plan is created for the func on itself and
stored in the execu on plan cache.
31. What are the different statements allowed in a mul statement func on?
Statements allowed in a mul statement func on:

 Assignment
 Control of flow
 Declare statement defining data variables
 Select statement containing select list
 TABLE variables
 Calling Extended Procedures using Execute statement
32. What are the different types of stored procedures in SQL Server?
A stored procedure can take input parameters, return tabular or scalar results and messages
to the client. Types are as follows:
 System
 Temporary

 Remote
 Extended
 User-defined
33. What are the special tables used with trigger?
DML trigger statements use two special tables: the deleted table and the inserted tables.
SQL Server automa cally creates and manages these tables. Func ons performed by them
are as follows:
 Extend referen al integrity between tables.
 Insert or update data in base tables underlying a view.
 Test for errors and take ac on based on the error.
 Find the difference between the state of a table before and a er a data modifica on
and take ac ons based on that difference
34. Why do we need snapshot isola on in SQL Server?
The term “snapshot” reflects the fact that all queries in the transac on see the same
version, or snapshot, of the database, based on the state of the database at the moment in
me when the transac on begins. Snapshot isola on uses an op mis c concurrency model.
If a snapshot transac on a empts to commit modifica ons to data that has changed since
the transac on began, the transac on will roll back and an error will be raised. When the
SNAPSHOT isola on level is enabled, each me a row is updated, the SQL Server Database
Engine stores a copy of the original row in tempdb, and adds a transac on sequence number
to the row.
35. Explain different types of lock mode in SQL Server?
 Shared (S): Used for read opera ons that do not change or update data, such as a
SELECT statement.
 Update (U): Used on resources that can be updated.
 Exclusive (X): Used for data-modifica on opera ons, such as INSERT, UPDATE, or
DELETE.
 Intent: Used to establish a lock hierarchy.
36. What are the key features of column store technology?
The key characteris cs of SQL Server column store technology are as follows:
 Columnar data format
 Faster query results
 Key columns – There is no concept of key columns in a columnstore index
 Par oning – Columnstore indexes works with table par oning
 Record Size – The index key record size limita on of 900 bytes also does not apply to
columnstore indexes
37. How to detect and reduce fragmenta on in SQL Server?
Storing data non-con guously on disk is known as fragmenta on.
sys.dm_db_index_physical_stats is used to detect fragmenta on.
When an index is fragmented in a way that the fragmenta on is affec ng query
performance, there are three choices for reducing fragmenta on:
 Drop and re-create the clustered index. Re-crea ng a clustered index redistributes
the data and results in full data pages.
 Use ALTER INDEX REORGANIZE
 Use ALTER INDEX REBUILD
38. Explain the different transac on modes supported by SQL Server?
Microso ’s SQL Server provides support for transac ons in three different modes of
opera on. They are as follows:
 Implicit: If a transac on is implicitly started, then the transac on will con nue un l
it’s either fully commi ed or un l the transac on is rolled back
 Explicit: Explicit mode is most commonly used in triggers, stored procedures and
applica on programs
 Autocommit: In autocommit mode, each SQL statement is treated as a separate
transac on
39. Explain concept of principals in SQL Server?
Principals are en es that can request SQL Server resources. Types of principals are as
follows:
 Windows Level-It includes window domain and window local login
 SQL Server Level
 Database Level-It includes database role, user and applica on role.
40. Explain few server level roles in SQL Server?
SQL Server provides server-level roles to help you manage the permissions on a server
 sysadmin: Members of the sysadmin fixed server role can perform any ac vity in the
server
 processadmin: Members of the processadmin fixed server role can end processes
that are running in an instance of SQL Server
 diskadmin: The diskadmin fixed server role is used for managing disk files.
 dbcreator: Members of the dbcreator fixed server role can create, alter, drop, and
restore any database.
41. What is the difference between contained and par ally contained database?
A contained database is a database that is isolated from other databases and from the
instance of SQL Server that hosts the database. A par ally contained database is a contained
database that can allow some features that cross the database boundary. SQL Server
includes the ability to determine when the containment boundary is crossed.
42. Explain some of the best prac ces to be adopted while using SQL Server?

Some of best prac ces are as follows:


 Avoid using Nchar or nVarchar unless you need to store Unicode characters
 Use char for fixed length data
 Avoid using SQL variant data type
 Use varchar(max) instead of text
 Use @@Error or try..catch to handle the errors
43. What is CLR Integra on?
The common language run me (CLR) is the heart of the Microso .NET Framework and
provides the execu on environment for all .NET Framework code. Code that runs within the
CLR is referred to as managed code. The CLR provides various func ons and services
required for program execu on, including just-in- me (JIT) compila on, alloca ng and
managing memory, enforcing type safety, excep on handling, thread management, and
security.
44. Explain two forms of APPLY operator?
The APPLY operator allows you to invoke a table-valued func on for each row returned by an
outer table expression of a query. Two forms of APPLY are as follows:
 CROSS APPLY: It returns only those rows in the outer table for which the table value
func on returns data.
 OUTER APPLY: It returns all rows from the outer table, whether or not the func on
returns data for a specific row
45. What is the difference between SET and SELECT statement in SQL Server?
Set is ANSI standard for assigning values to variables. Select can be used when assigning
values to mul ple variables. SET is slower than SELECT. SELECT is mainly to return data. SET
is mainly to assign values to local variables.
46. What is the difference between PIVOT and UNPIVOT clause in SQL Server?
PIVOT rotates a table-valued expression by turning the unique values from one column in
the expression into mul ple columns in the output, and performs aggrega ons where they
are required on any remaining column values that are wanted in the final output. UNPIVOT
performs the opposite opera on to PIVOT by rota ng columns of a table-valued expression
into column values.
47. What is the purpose of MERGE statement in SQL Server?
MERGE performs insert, update, or delete opera ons on a target table based on the results
of a join with a source table. When used a er MERGE, @@ROWCOUNT (Transact-SQL)
returns the total number of rows inserted, updated, and deleted to the client. The MERGE
statement requires a semicolon (;) as a statement terminator.
48. Explain Iden ty property in SQL Server?
Iden ty property creates an iden ty column in a table. This property is used with the
CREATE TABLE and ALTER TABLE Transact-SQL statements. Only one iden ty column can be
created per table. Iden ty columns can be used for genera ng key values.
49. What are SQL Server specific data types?
They are as follows:
 XML – Used for storing semi structured data
 Geospa al – This type represents data in a round-earth coordinate system
 HierarchyId – It is used to represent posi on in a hierarchy
 FILESTREAM – It is used to store unstructured data
50. What are different isola on levels for transac ons?
The different isola on levels are as follows:

 Uncommi ed Read: This lets a transac on read any data currently on a data page,
whether or not that data has been commi ed
 Commi ed Read: This ensures that an opera on will never read data another
applica on has changed but not yet commi ed
 Repeatable Read: This isola on level adds to the proper es of Commi ed Read by
ensuring that if a transac on revisits data or if a query is reissued, the data will not
have changed
 Serializable: This isola on level ensures that if a query is reissued, no data will have
changed and no new rows will appear in the interim

You might also like