Monday 15 February 2016

T-SQL interview Question on Trigger

Can we fire a trigger manually ?

No you cannot fire a trigger manually.Make use of Store procedure to execute it manually

Thursday 23 July 2015

T-SQL interview question rowcount

How to get the last record value in sql server without using MAX/TOP clause?
Solution :

Using the below query.
set rowcount 1

select * from employees order by id desc

T-SQL interview question 2

2) Consider a Table name A which has below records

ID
---
5
5
5
5
5
Consider another table B which has below records

ID
--
5
5
5
5
5
5
5
5
How many rows will be returned by each of the below queries
a) select * from A inner join B on A.id = b.ID
b) select * from A left join B on A.id = b.ID
c) select * from A right join B on A.id = b.ID

Solution :

a) 40 rows
b) 40 rows
c) 40 rows


T-SQL interview question Identity Column

1) If a table is having only one identity column how can we insert records into this table?
Answer :

Consider table customer which is created with below statement in sql server
create table customer
( id int identity(1,1))
Now to insert  records into this table we can do it in two ways:
a) INSERT INTO customer DEFAULT VALUES
b)
SET IDENTITY_INSERT dbo.customer ON
INSERT INTO customer (id)
values (1),(2),(3)