Click here to get free chapters (PDF) in the mailbox
Please read the Introductory Post before continue reading interview question and answers.
List of all the Interview Questions and Answers Series blogs
What is a Stored Procedure?
A stored procedure is a named group of SQL statements that have been previously created and stored in the server database. Stored procedures accept input parameters so that a single procedure can be used over the network by several clients using different input data. And when the procedure is modified, all clients automatically get the new version. Stored procedures reduce network traffic and improve performance. Stored procedures can be used to help ensure the integrity of the database.
e.g. sp_helpdb, sp_renamedb, sp_depends etc.
What is a Trigger?
A trigger is a SQL procedure that initiates an action when an event (INSERT, DELETE or UPDATE) occurs. Triggers are stored in and managed by the DBMS. Triggers are used to maintain the referential integrity of data by changing the data in a systematic fashion. A trigger cannot be called or executed; DBMS automatically fires the trigger as a result of a data modification to the associated table. Triggers can be considered to be similar to stored procedures in that both consist of procedural logic that is stored at the database level. Stored procedures, however, are not event-drive and are not attached to a specific table as triggers are. Stored procedures are explicitly executed by invoking a CALL to the procedure while triggers are implicitly executed. In addition, triggers can also execute stored procedures.
Nested Trigger: A trigger can also contain INSERT, UPDATE and DELETE logic within itself; so when the trigger is fired because of data modification, it can also cause another data modification, thereby firing another trigger. A trigger that contains data modification logic within itself is called a nested trigger. (Read more here)
What are the Different Types of Triggers?
There are two types of Triggers.
1)Â Â Â Â Â DML Trigger
There are two types of DML Triggers
1.Instead of Trigger
Instead of Triggers are fired in place of the triggering action such as an insert, update, or delete.
2. After Trigger
After triggers execute following the triggering action, such as an insert, update, or delete.
2)Â Â Â Â Â DDL Trigger
This type of trigger is fired against Drop Table, Create Table, Alter Table or Login events. DDL Triggers are always After Triggers.
What is a View?
A simple view can be thought of as a subset of a table. It can be used for retrieving data as well as updating or deleting rows. Rows updated or deleted in the view are updated or deleted in the table the view was created with. It should also be noted that as data in the original table changes, so does the data in the view as views are the way to look at parts of the original table. The results of using a view are not permanently stored in the database. The data accessed through a view is actually constructed using standard T-SQL select command and can come from one to many different base tables or even other views.
What is an Index?
An index is a physical structure containing pointers to the data. Indices are created in an existing table to locate rows more quickly and efficiently. It is possible to create an index on one or more columns of a table, and each index is given a name. The users cannot see the indexes; they are just used to speed up queries. Effective indexes are one of the best ways to improve performance in a database application. A table scan happens when there is no index available to help a query. In a table scan, the SQL Server examines every row in the table to satisfy the query results. Table scans are sometimes unavoidable, but on large tables, scans have a terrific impact on performance.
What is a Linked Server?
Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server databases using T-SQL Statements. With a linked server, you can create very clean, easy–to-follow SQL statements that allow remote data to be retrieved, joined and combined with local data. Stored Procedures sp_addlinkedserver, sp_addlinkedsrvlogin will be used to add new Linked Server. (Read more here)
What is a Cursor?
A cursor is a database object used by applications to manipulate data in a set on a row-by-row basis, instead of the typical SQL commands that operate on all the rows in the set at one time.
In order to work with a cursor, we need to perform some steps in the following order:
- Declare cursor
- Open cursor
- Fetch row from the cursor
- Process fetched row
- Close cursor
- Deallocate cursor (Read more here)
What is Collation?
Collation refers to a set of rules that determine how data is sorted and compared. Character data is sorted using rules that define the correct character sequence with options for specifying case sensitivity, accent marks, Kana character types, and character width. (Read more here)
List of all the Interview Questions and Answers Series blogs
Reference: Pinal Dave (https://blog.sqlauthority.com)
47 Comments. Leave new
Thank You Sir,
It will Help in Many interview
sir ,out of 20 rows ,i want select select 5 row ,so what query for it,
anyone can tell me?
select Top(5) * from table name..
out of 20 rows ,i want select select 5 row ,so what query for it:::
select Top(5) * from table name..
Hello Sir..
I am working in DB testing… Can you plz publish any articles which helps for Database testing..
Thanks…
nice one
by srinivasan sampath
its a very helpful..specially who is the just start learning sql like me. i started learn like 3 month ago..i need to know more about sql server than i will seat down interview..please helpme out sir how i can seat with interviw.
It is SO VERY HELPFUL AND VERY EASY TO UNDERSTAND. Thank you so much!
thanks for all it very Easy to understand all
Very much usefull
it was really helpfull .. good one ..
sir, what is mean by query?
Thanks Sir . I am going for an interview tomorrow this will defenately help me . Thanks
this is nice site for sql
Thanks Sir, all it very Easy to understand.
I Agree
Thanks everyone.
Hi Sir,
My name is Vinod.I am a sql developer since 2 years and yesterday i went to an interview.I am answering all the question but they are asking one thing that what is a collation…i did’t answer to that question.and i refered in your website.I am not able to understanding what is the exact functionality and what it means how can it is use full..can u please explain from basic onwards
Nice Question Very Helpfull
I am glad that you liked it Ritesh.
thnks really gr8….reallly helpfull even basic fundamental
Thank you pinal dave.this site very usefull
Great work and easily understandable. Thanks.
Thanks Rajan.