Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
408 views

SQL Tricky Questions

The document discusses various SQL concepts including: - The difference between truncate and delete statements and their effects on triggers and transaction logs. - The different types of joins that can be used in SQL queries. - The two types of indexes - clustered and nonclustered - and how they store and organize data in tables. - The isolation levels and constraints that can be set in SQL Server. - The difference between where and having clauses when used with group by statements. - How errors are handled in SQL Server Integration Services packages. - The key differences between primary keys and unique keys. - What columns defaults cannot be bound to and how to create and apply defaults. - What blocking is in SQL

Uploaded by

Komo Mo
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
408 views

SQL Tricky Questions

The document discusses various SQL concepts including: - The difference between truncate and delete statements and their effects on triggers and transaction logs. - The different types of joins that can be used in SQL queries. - The two types of indexes - clustered and nonclustered - and how they store and organize data in tables. - The isolation levels and constraints that can be set in SQL Server. - The difference between where and having clauses when used with group by statements. - How errors are handled in SQL Server Integration Services packages. - The key differences between primary keys and unique keys. - What columns defaults cannot be bound to and how to create and apply defaults. - What blocking is in SQL

Uploaded by

Komo Mo
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 4

1)

What is the difference between truncate and Delete?

Delete will fire delete trigger, truncate will not.


The DELETE statement removes rows one at a time and records an entry in
the transaction log for each deleted row. TRUNCATE TABLE removes the data
by deallocating the data pages used to store the table data and records only
the page deallocations in the transaction log.Once you truncate you cant
rollback.
If there is an identity column in the table truncate will reset identity to 1,
delete will not.
2)

Name the different type of joins

Inner Join
Outer Join (Left Outer Join and Right Outer Join)
Cross join
Self-Join
3)

What is an Index?

There are two types of indexes. Clustered index and Non Clustered Index. A
table can have only 1 Clustered Index while it can have up to 249 & 999
nonclustered indexes on SQL Server 2005 & 2008 respectively. A clustered
index stores the actual data rows at the leaf level of the index. Indexes can
make Select statement fast but delete, update and insert statements will get
slow.

4)

a)

What are different types of Isolation levels in SQL Server

READ UNCOMMITTED

b)

READ COMMITTED

c)

REPEATABLE READ

d)

SERIALIZABLE

e)

SNAPSHOT

5)

What are different types of constraints in SQL Server?

Primary key Constraint


Foreign key Constraint
Check Constraint
Unique Key Constraint
6)

What is the difference between where and having clause?

A having clause is typically used when you use group by clause.

Example:

SELECT titles.pub_id, AVG(titles.price)


FROM titles INNER JOIN publishers
ON titles.pub_id = publishers.pub_id

WHERE publishers.state = CA
GROUP BY titles.pub_id
HAVING AVG(titles.price) > 10

WHERE clause is applied first to the individual rows in the tables . Only the
rows that meet the conditions in the WHERE clause are grouped. The HAVING
clause is then applied to the rows in the result set.

7)

How would you do Error Handling in SSIS?

SSIS package could mainly have two types of errors

a) Procedure Error: Can be handled in Control flow through the precedence


control and redirecting the execution flow.

b) Data Error: is handled in DATA FLOW TASK buy redirecting the data flow
using Error Output of a component.

8)

What is the difference between a primary key and a unique key?

Both primary key and unique enforce uniqueness of the column on which
they are defined. But by default primary key creates a clustered index on the
column. Major difference is that, primary key does not allow NULLs, but
unique key allows NULL.

9)
What are defaults? Is there a column to which a default cannot be
bound?

A default is a value that will be used by a column, if no value is supplied to


that column while inserting data. IDENTITY columns and timestamp columns
cant have defaults bound to them.

You can create default and then bind a column to them.

Example:

//This will create default ZipCode in database

Create default ZipCode as 78746

//This will bind the default we created to a column PostalCode in table


EmployeeData
sp_bindefault ZipCode, EmployeeData.PostalCode
10) What is SQL Blocking?
Blocking happens when one connection from an application holds a lock and
a second connection requires a conflicting lock type. This forces the second
connection to wait, blocked on the first.

You might also like