Archive for the ‘Database’ Category

Sql server date time functionality

August 20, 2008

Select * from users where convert(char,createddate,101)=’07/29/2008′

select cast(getdate() as char)

Resetting the table identity values

August 20, 2008

To reset the identity value in database table

 

Syntax: DBCC checkident (tablename, reseed, 0)

 

DBCC checkident can reseed the value of the table. For e.g.: our table has 25 records with 25 as last identity. If we want next record to have identity has 35 we need to run following T-SQL

 

DBCC checkidetnt (tablename, reseed, 34)

 

Disadvantage: It will violate the uniqueness.

Copying one table values into another table.

August 20, 2008

INSERT INTO TestTable (FirstName, LastName)
SELECT FirstName, LastName
FROM Person.Contact
WHERE EmailPromotion = 2
–Verify that Data in TestTable
SELECT FirstName, LastName
FROM TestTable

IF it is in different database.
INSERT INTO SmithNephewStoreFront.dbo.category ( [Name],parentcategoryID)
SELECT  category,subcatid
FROM endo.dbo.category
WHERE catid = 2

resetting the identity column in the database table .

August 20, 2008

 

DBCC CHECKIDENT (category, RESEED, 0)