Interview Questions → SQL SERVER → SQL Server Questionnaire I
SQL Server Questionnaire I
BEGIN TRAN
TRUNCATE TABLE Test_Match
-- statement will return empty Test_Match table
SELECT * FROM Test_Match
ROLLBACK
--statement will return Test_Match table with original data
SELECT * FROM Test_Match
-- declaring 2 temp table #Temp and #TempAddress
Create Table #Temp
(
PK_ID int identity(1,1),
sName Varchar(50)
)
Create Table #TempAddress
(
PK_ID int identity(1,1),
PersonID int,
Address Varchar(100)
)
-- Inserting the value in both the tables
Insert Into #Temp Values('Karan')
Insert Into #Temp Values('Gupta')
Insert Into #Temp Values('Karan')
Insert Into #Temp Values('Karan')
| PK_ID | sName |
|---|
| 1 | Karan |
| 2 | Gupta |
| 3 | Karan |
| 4 | Karan |
Insert Into #TempAddress Values(1,'Address1')
Insert Into #TempAddress Values(2,'Address2')
Insert Into #TempAddress Values(3,'Address3')
| PK_ID | PersonID | Address |
|---|
| 1 | 1 | Address1 |
| 2 | 2 | Address2 |
| 3 | 3 | Address3 |
select Address from #TempAddress a where a.PersonID in (select PK_ID from #Temp b where b.PK_ID = a.PersonID)
| Address |
|---|
| Address1 |
| Address2 |
| Address3 |
Drop Table #Temp
Drop Table #TempAddress
Begin Transaction
update tblMessageCode Set MessageCode = 'tst'
Create Proc #test
as
select * from <table_Name>
Create Proc ##test
as
select * from <table_Name>
| PK_ID | sName | sAddress |
|---|
| 1 | Name1 | Address1 |
| 2 | Name2 | Address2 |
Create View v_tbl_Test
with schemabinding
as
select PK_ID, sName, sAddress
from dbo.tbl_Test
Create Unique clustered index id_v_tbl_Test
on v_tbl_Test(PK_ID)