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
Simply Superb for quick glance…..thanking you alot.pinaldave………………
Thanks for the post. This reminds me to my college apply. The professor asked the big question: -What is the mouse? I failed the give a correct whole answer. :-)
Thanks alot Pinal..really simplified lots fo things :)
i would really appreciate if you will put some performance tunning or any MCDBA questions here and ask to viewers how or what will be the solution.
i really appreciate you that you really done a big job. and the viewer gets the biggest solution here.
Ur post is really helpful.. Thanks a lot….
Thanks Pinal, People(including me) who are going for an interview they use it as notes.
Great comprehensive list of questions to help jog the old grey matter – Thanks!
Simple superb :)
Thanks!!!
Very useful……
Hi Pinal, I think you may want to revise the explanation related to DDL triggers as the actual scope of events they can fire against is far broader then mentioned here. DDL triggers fire in response to a variety of Data Definition Language (DDL) events, not limited to table scope.
This BOL link contains the details: https://docs.microsoft.com/en-us/sql/relational-databases/triggers/ddl-event-groups?view=sql-server-2017
Regards,
Hrvoje
I completely agree with you. I will for sure write follow up on this subject.
Thanks again Hrvoje, your comments are always very insightful and helpful.
I believe Logon trigger should also be in your list apart from DDL & DML.
Very good site. When ever I got sql related quries doubt, first I will try SQLauthority and 95% I will get answer from here and I am very happy – Raghu
Excellent
i want real time programmatic question and answers in stored procedure?
Excellent !!!! Easy to understand .when ever i look in to sql authority for clearing my queries i am forced to look into other concepts by me along with my queries .simply good.
very helpful site for beginners and fresher thank a lot Mr Pinal
Husssain
Thanks a lot ……..Pinal
very useful.. thanks alot
Nice Description
Thank you.You are helping lot