#.
|
Table
Variable
|
Temp
Table
|
1
|
It stored in primary memory(ie. in RAM)
|
It stored in system database(ie. In msdb)
|
2
|
It has batch scope only, ie. Till the current t-sql stmt to be execute
|
It has the scope till the query window close, In case of local temp
table and has the scope till all the SSMS query windows close in case of
global temp table
|
3
|
Table variables can’t use within select into clause
|
Temp tables can be used within select into clause
|
4
|
Table variables gives better performance than temp table, because
they stores in primary memory (ie. In RAM)
|
Temp tables not gives better performance than table variables,
because it stores in hard disk
|
5
|
We can’t explicitly drop the table variables
|
We can explicitly drop the temp tables
|
Sunday, 4 May 2014
Diffence between Table Variable and Temp Table
Difference between UNION and UNION ALL ?
UNION and UNION ALL both are used to combine the results sets into one single results set, But following are the difference between the both operators.
#.
|
UNION
|
UNION ALL
|
1
|
UNION removes duplicate records from the two or more results sets
|
UNION ALL doen’t remove duplicate records from the two or more results
sets
|
2
|
UNION Sorts the data from the
results sets
|
UNION ALL doesn’t Sorts the data from the results sets
|
3
|
By compare with union all, union is much
less performance. Because of it must scan the result for duplicates
|
UNION ALL performance is more comparing with UNION
|
SET Operators in T-SQL
Set Operators :
It is used to combine multiple results sets into one single result set.
There are 3 set operators in T-SQL
1) UNION/UNION ALL
2) EXCEPT
3) INTERSECT
UNION/UNION ALL :
----------------------------
It is used to combine two or more result sets into one single result set by with or without duplicates
(ie, UNION doesn't allow null values, but UNION ALL allows null values)
Example:
<<ResultSet>>
UNION or UNION ALL
<<ResultSet>>
EXCEPT:
------------
It takes the data from one result set where there is no matching in another result set.
Example:
<<ResultSet>>
EXCEPT
<<ResultSet>>
INTERSECT:
----------------
It takes the data from the result sets which are in common
Example:
<<ResultSet>>
INTERSECT
<<ResultSet>>
It is used to combine multiple results sets into one single result set.
There are 3 set operators in T-SQL
1) UNION/UNION ALL
2) EXCEPT
3) INTERSECT
UNION/UNION ALL :
----------------------------
It is used to combine two or more result sets into one single result set by with or without duplicates
(ie, UNION doesn't allow null values, but UNION ALL allows null values)
Example:
<<ResultSet>>
UNION or UNION ALL
<<ResultSet>>
EXCEPT:
------------
It takes the data from one result set where there is no matching in another result set.
Example:
<<ResultSet>>
EXCEPT
<<ResultSet>>
INTERSECT:
----------------
It takes the data from the result sets which are in common
Example:
<<ResultSet>>
INTERSECT
<<ResultSet>>
How to change the Identity Column value ?
Before Change the Identity value(ProductID column) from the Product Table
-- To set the new identity value on the Product Table
DBCC CHECKIDENT ('Product', RESEED, 10)
Execution Results as follows
Checking identity information: current identity value '10', current column value '10'.
DBCC execution completed.
DBCC execution completed.
To insert a new record in the product table, to test the next identity value
insert into Product values ('Mat',200)
After Change the Identity value
Subscribe to:
Posts (Atom)