Showing posts with label Data. Show all posts
Showing posts with label Data. Show all posts

Sunday 4 May 2014

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>>


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.

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

 



How to check the current identiy value in a table ?


"DBCC CHECKIDENT" Statement is used to check the current identity value for the specified table and if requires then can modify/change the identity value on a identity column.

Syntax:
DBCC CHECKIDENT ('Table_Name' [ , { NORESEED  | { RESEED [ , new_reseed_value ] } } ] )

Example:
CREATE TABLE Product(ProductID int identity(1,1), ProductName varchar(20), Price decimal(18,6) )
INSERT INTO Product VALUES ('Book',150.10),('Pen',35.50)
-- To check the current maximum identity value in the column, execute the following statement
DBCC CHECKIDENT ('Product', NORESEED)

Friday 25 April 2014

SQL Server 2008 New Features

Microsoft SQL Server 2008 introduces several important new Transact SQL programmability features and enhances some existing ones
 
Following is the list of key new features

1.Initializing variables
2.Compound assignment operators
3.Enhanced CONVERT function
4.New date and time data types
5.New date and time functions
6.The MERGE statement
7.Grouping sets
8.Table valued parameters
9.Large user-defined types
10.Table value constructor support
11.DDL trigger enhancements
12.Sparse columns
13.Filtered indexes

We will provide the information in detail in next section.

Thursday 24 April 2014

How to import data directly from T-SQL commands without using SQL Server Integration Services?

There are so many ways to import data directly using T-SQL.

Here listed couple of commands which helps to load the Data quickly into the Database:
  • BCP
  • Bulk Insert
  • OpenRowSet
  • OPENDATASOURCE
  • OPENQUERY