Tricky SQL Interview Questions
SQL Interview Questions
How to insert 10 default
records in SQL Table. For example suppose we have Student Table with columns
Name, Address and other. Write a query to insert default value in one go.
INSERT INTO mytable DEFAULT VALUES
GO 10
What is GO keyword in
SQL?
GO keyword is not associated with SQL but it is property of
SQL Server Management Studio. GO can be understand simply for following
example.
Student with Mark on their T-Shirt 1,2,3,4,5,6,7,8,9,10 and 11,12….20
are ready to run in an event but when it is said student from 1 to 10 Go then
they start running but students from 11 to 20 wait until they are not said.
So it is batch separator in SQL.
What is Temp table
and Temp variable in SQL and why they are used?
1.
Temp Table store location is Tempdb while Temp
variable storage location if not specified is current database.
2.
Table variables can only be accessed within the
batch and scope in which they are declared. Temp Tables are accessible within
child batches.
3.
Temp table can’t be used in function while Table
variable can be used.
4.
Table variable don’t support Identity insert,
altered or truncated while Temp table can do it.
5.
Indexing is similar on Temp table as normal
table while Temp variable can have indexing only when primary and unique key is
defined.
Consider a table
Human with Name and Gender as columns, write a query to update male to female
and vice versa.
Update Human case when Gender=’male’ then ‘Female’ else ‘Male’ end
How Trigger works?
As per the syntax of Trigger
create trigger [trigger_name]
[before | after]
{insert | update | delete}
on [table_name]
[for each row]
[trigger_body]
It run on three events happens on table insert, update and
delete. So when if we insert any data in table it will invoke insert trigger
which is free to execute before or after.
Comments
Post a Comment