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
Thanks a Lot
U Do a Great Things.
Hi
I am very much interested in become SQL programmer. And obtain MS certification. I have knowledge of programming C# and ASP.Net but not in the deep. Please let me how long it will take and how many hours I need to put in to this subject daily basis. Where I can find good materials. What are the all good methods follow. Is there big scope in this field??
Sorry for all the questions. I thought this is the good place ask
Thanks in advance
D
Hello Sir, I want to develop a Gender database using SQL Server. And I want to know more in Normalizing. please send any Sample .
Thank U .
Hell sir,
I want to copy table with same structure with different name in same database. I tried “Select * into ‘newtblname’ from ‘totblname’ but this will not copy foreign key constraints.
Is there any other way to copy all structure.
Thanks
Generate Script of the table and rename the table name when running it
Hi Vikram,
Try this below Query,
Select * from ‘Newtblname’ from ‘totblname’
where 1=2
ITs works Fine.
Note that it wont copy the indexes
You mentioned “TRUNCATE cannot be rolled back”
But it can be rolled back ..
Can you please clear what you want to say?
Truncate call be rolledback if it is used inside a transaction
truncate is nthg but “permenent deletion”
its not rolled back again.
if u r use “delete” command then u can go to “roolback”.because delete is temporary deletion purpose .
I am having 3.5 years of experience in Sql server Development. can you tell me what kind of postition i can try to prior level?
There is no place like your blog which clearly describes the concepts with examples. I love your site so much that i no more look anywher except your blog.. i wish you put more and more questions and be helpful for all self starters and learners.
Nice work.. really nice information at one place.. Thanks
Hi Pinal Sir,
I m bit confused.
I m working as a Software Engineer. Currently working on VB and SQL Server. Basicall my work is in SQL Server, writing SP, triggers, backup restore. I m much more interested in SQL Server. I wana work Oracle or SQL Developer track.
But i m not getting what to do next??
Can u guide me little bit……..
Good Job Pinal
Practice…Practice…Practice…. This is the only way you can gain confidence on any programming language. I would recommend “Beginning SQL server 2005 programming” book. Don’t even miss single line. You should be good in 1 month. Seriously!
thank u very much , but we need more typical and technical questions
Hi Pinal Dave,
you are really great. I have got more solution related sql server. kindly provide me full information of BI. which type of job i can get after getting command on BI in sql server 2008. can i use all BI package in sql server 2008 express edition
reply asap.
thanks in advance
sakendra kumar
Hi Pinal Dave,
Thank u so much .. Its very much usual for preparing interviews. I am having 1 year Exp in SQL , can u please send me some more interview qusetions ..
Thanks a lot for ur wonderful Effort..
Thanks ,
Chitra.
Hi Pinal,
I am preparing for sql server administration cource and simultaneously i want to attending interviews . So please help me for this . I need interview questions and answers from every toipic .
can you plz send me the Q and Answers to my mail
Hi Pinal,
Thanks so much for the lovely article that you have posted. I am actually preparing for the MCTS in sql server 2005 and want your help and guidence. Please guide me through the process of preparation and also please tell me how will it benefit me in my current role in the company as a Dotnet developer .
Many Thanks,
Dinesh.
HI,
I have plan to write the MCTS 70-433.you have any material for the above exam.
please advice
Thanks
Babu.K
Hi Pinal,
In sql stored procedure i am using dynamic sql based on input parameters.
But it is not showing any database fields in crystal report [using C#].
So is there any way that i can get the output fields in stored prcedure & it can be displayed in database fields while creating crystal report in C#?
Kindly guide me. I tried with lots of solutions but it doesn’t work, so please give one example.
Thanks
Riddhi
Hi Riddhi,
It’s not a matter that you are using dynamic procedure, matter is that first of all you create stored procedure and execute it into database it self. If it gives result on the basis of your parameter, after then go to crystal report->file->new blank report->create new connection->select OLE DB (ADO)->Microsoft OLE DB Provider fro SQL Server->click on Next Button->select server name->userid->password->database in which you have created stored procedure ->Next->Finish
Now you have a tree available in left pan.
you can select database ->dbo->stored procedure->select your stored and click on (>) button. now you have a window for parameter->after putting the value into parameter you click on OK button.
after then go on View menu->Field Explorer->Click on database field->now your all field are available which your dynamic table returns.
Since i haven’t your email id, so how it possible to display Print screen. If you have any further query. Keep in touch.
Thanks
Sakendar Kumar (MCA)
You can’t desing a report based on the procedure whose result is dynamic. If, based on the input parameters the number of columns can be changed, it is not possible to design a report.
One option is to have as many procedures as possible for each combination of input values
Dear Sir,
I want to generate script of a table by command not by wizard facility.is there any command by which i can do this
Thanks
Preeti Agarwal
Hi Preeti,
You can try following command to generate script
C:\Program Files\Microsoft SQL Server\90\COM>tablediff.exe
Thanks,
Janki
Hi Preeti agarwal,
first of all you create my procedure
and execute one by one like :-
GenerateScript yourtablename
If your problem are still not solved then keep in touch
my email id:– [email removed for privacy and security purpose]
Create Procedure GenerateScript (
@tableName varchar(100))
as
If exists (Select * from Information_Schema.COLUMNS where Table_Name= @tableName)
Begin
declare @sql varchar(8000)
declare @table varchar(100)
declare @cols table (datatype varchar(50))
insert into @cols values(‘bit’)
insert into @cols values(‘binary’)
insert into @cols values(‘bigint’)
insert into @cols values(‘int’)
insert into @cols values(‘float’)
insert into @cols values(‘datetime’)
insert into @cols values(‘text’)
insert into @cols values(‘image’)
insert into @cols values(‘uniqueidentifier’)
insert into @cols values(‘smalldatetime’)
insert into @cols values(‘tinyint’)
insert into @cols values(‘smallint’)
insert into @cols values(‘sql_variant’)
set @sql=”
Select @sql=@sql+
case when charindex(‘(‘,@sql,1)<=0 then '(' else '' end +Column_Name + ' ' +Data_Type +
case when Data_Type in (Select datatype from @cols) then '' else '(' end+
case when data_type in ('real','money','decimal','numeric') then cast(isnull(numeric_precision,'') as varchar)+','+
case when data_type in ('real','money','decimal','numeric') then cast(isnull(Numeric_Scale,'') as varchar) end
when data_type in ('char','nvarchar','varchar','nchar') then cast(isnull(Character_Maximum_Length,'') as varchar) else '' end+
case when Data_Type in (Select datatype from @cols)then '' else ')' end+
case when Is_Nullable='No' then ' Not null,' else ' null,' end
from Information_Schema.COLUMNS where Table_Name=@tableName
select @table= 'Create table ' + table_Name from Information_Schema.COLUMNS where table_Name=@tableName
select @sql=@table + substring(@sql,1,len(@sql)-1) +' )'
select @sql as DDL
End
Else
Select 'The table '+@tableName + ' does not exist'