Click here to get free chapters (PDF) in the mailbox
SQL SERVER – 2008 – Interview Questions and Answers Complete List Download
1) General Questions of SQL SERVER
What is RDBMS?
Relational Data Base Management Systems (RDBMS) are database management systems that maintain data records and indices in tables. Relationships may be created and maintained across and among the data and tables. In a relational database, relationships between data items are expressed by means of tables. Interdependencies among these tables are expressed by data values rather than by pointers. This allows a high degree of data independence. An RDBMS has the capability to recombine the data items from different files, providing powerful tools for data usage. (Read More Here)
What are the properties of the Relational tables?
Relational tables have six properties:
- Values are atomic.
- Column values are of the same kind.
- Each row is unique.
- The sequence of columns is insignificant.
- The sequence of rows is insignificant.
- Each column must have a unique name.
What is Normalization?
Database normalization is a data design and organization process applied to data structures based on rules that help building relational databases. In relational database design, the process of organizing data to minimize redundancy is called normalization. Normalization usually involves dividing a database into two or more tables and defining relationships between the tables. The objective is to isolate data so that additions, deletions, and modifications of a field can be made in just one table and then propagated through the rest of the database via the defined relationships.
What are different normalization forms?
1NF: Eliminate Repeating Groups
Make a separate table for each set of related attributes, and give each table a primary key. Each field contains at most one value from its attribute domain.
2NF: Eliminate Redundant Data
If an attribute depends on only part of a multi-valued key, remove it to a separate table.
3NF: Eliminate Columns Not Dependent On Key
If attributes do not contribute to a description of the key, remove them to a separate table. All attributes must be directly dependent on the primary key. (Read More Here)
BCNF: Boyce-Codd Normal Form
If there are non-trivial dependencies between candidate key attributes, separate them out into distinct tables.
4NF: Isolate Independent Multiple Relationships
No table may contain two or more 1:n or n:m relationships that are not directly related.
5NF: Isolate Semantically Related Multiple Relationships
There may be practical constrains on information that justify separating logically related many-to-many relationships.
ONF: Optimal Normal Form
A model limited to only simple (elemental) facts, as expressed in Object Role Model notation.
DKNF: Domain-Key Normal Form
A model free from all modification anomalies is said to be in DKNF.
Remember, these normalization guidelines are cumulative. For a database to be in 3NF, it must first fulfill all the criteria of a 2NF and 1NF database.
What is De-normalization?
De-normalization is the process of attempting to optimize the performance of a database by adding redundant data. It is sometimes necessary because current DBMSs implement the relational model poorly. A true relational DBMS would allow for a fully normalized database at the logical level, while providing physical storage of data that is tuned for high performance. De-normalization is a technique to move from higher to lower normal forms of database modeling in order to speed up database access.
What is 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 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 viewed as 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 is 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 data in the view, as views are the way to look at part 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 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 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 dbs 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 Procedure sp_addlinkedserver
, sp_addlinkedsrvlogin
will be used add new Linked Server. (Read More Here)
© Copyright 2000-2009 Pinal Dave. All Rights Reserved. SQLAuthority.com
Reference : Pinal Dave (https://blog.sqlauthority.com)
237 Comments. Leave new
my name is krishna i am doing dotnet course……..and i have learnt sqlserver 2005…….and i find difficult to write storedprocedurs and triggers to improve on that what i want to do………
What kind of difficulties do you face?
Post the code
Thanks a lot ……
Sir i am beginner in sqlserver 2005 ,i ve interest to learn lot of things what are the step that i want to follow,i want small tips for that sir
Hi,
Please checkout with ms sql tips ,its better use ful for beginner.
vijay
sir, i have a doubt. that is the maximum number of coloumns in a table.
2)
if we dont specify the lenght of datatype what happens?
than it will automatically take default its threshold value like
a data type in int. it contact maximum 8060 length but if u specify nothing it grow automatically in 8000 after it need 60 for buffering for transactions.
You should always specify the length.
See what happens you don’t do so
Hey come on man!!! What a great stuff.. Really good job.
Hi pinal,
Great collection…just a small request..
can i use these questions in my site…along with your reference and site url..?that would add value to my site..
thanks in advance..
hello sir,
your articles are very nice and all
the students of sql server are enjoyed a lot
Thanks!!!
Hi ,
I am enteresting in reading sql
can you send complex querry for me
hi all,
i like this site very much…
nd i need sql server interview question,if any has thn pls send me
hi pinal,
your site is very good.but can u expalin the concepts with examples…
it will be very useful for understanding..
Nice article….It is good for starters..
Awesome article.
Good Work Pinal.
Keep it up.
Hello Sir,
your articles are very nice and all
me and my friend enjoing ur artical
can u give me more logical interview questions on sql 2005 as i am going to appear for tester interviews……….
Hello Sir.
I want to get 100 rows from particular record and onward. in oracle i can use rownum and in mySql i have function limit … i want to know what is the ms-sql alternate for it.?
I want to get 100 rows onward to one particular data … how can i ?
Moderator: Please ignore previous comment.
@Vipul
You need to use ROWCOUNT key word and set a value to this.
Below is a sample example.
/* This is original Table */
declare @table table (id int identity , ename varchar(10))
/* This is final table */
declare @finaltable table (id int , ename varchar(10))
declare @count int
set @count = 1
/* insert sample data of 20 records in original table */
while @count 5
/* This is your final result */
select * from @finaltable
/* This is how you limit no of rows to be effected */ — IMPORTANT
set rowcount 10
insert into @finaltable select * from @table where id > 5
/* This is your final result */
select * from @finaltable
Let us know if this does not helps.
~ IM.
I use your code:
/* This is original Table */
declare @table table (id int identity , ename varchar(10))
/* This is final table */
declare @finaltable table (id int , ename varchar(10))
declare @count int
set @count = 1
/* insert sample data of 20 records in original table */
while @count = 5
/* This is your final result */
select * from @finaltable
/* This is how you limit no of rows to be effected */ — IMPORTANT
set rowcount 10
insert into @finaltable select * from @table where id > 5
/* This is your final result */
select * from @finaltable
–but this give output as like blank table
–Can you help me how to show ?
–How I insert sample data of 20 records in original table?
–Please help me
Thanks
Vasant
Make sure the table has data
To insert sample data to the table, refer this post
Regarding Vipul question,
how about using TOP ? for example:
SELECT TOP (100) FROM MY_TABLE ORDER BY COLUMN_A
May this could help.
Best regards,
Beta :)
F.Y.I
I also read recently in SQL 2008 books online that ROWCOUNT will not supported in the future versions of SQL Server. So please be careful when using it.
Best regards,
BB
Yes. Instead TOP operator should be used
@Vipul : You mean ‘get 100 rows from particular TABLE not record’
You can use the following syntax using TOP
Select TOP 100 from Table
TOP(100) might not work.
:)
Make sure you also use ORDER BY Clause when you use TOP operator
@Prash: Thanks for the correction :)
anyway, the works one for TOP syntax’s example (tested on SQL 2008) is like this:
SELECT TOP 100 * FROM TABLE
Note: ‘*’ means all rows available in that table, you can specify certain rows as required.
TOP is meaningless until ORDER BY clause is used