Search..

Wednesday, May 6, 2009

To list all the tables present in a database

This query used to list all the tables present in the database

SELECT name
FROM [servername].[databasename].dbo.sysobjects
WHERE xtype='u' order by name


You can also select the other details like
name, id, xtype, uid,info, status, base_schema_ver replinfo,parent_obj,crdate,ftcatid schema_ver,stats_schema_ver,type, userstat, sysstat, indexdel, refdate,version,deltrig,instrig updtrig,seltrig,category,cache

SELECT *
FROM [servername].[databasename].dbo.sysobjects
WHERE xtype='u'

Friday, April 10, 2009

Problem : we have a table in sql server and we have set a primary key to a column and auto increment is enabled, once u go on adding the records into the table the Identity column value is incremented by one, in case if u want to delete all the records in the table and re-insert the values the Identity column value will start from the previous value but not from zero.

Solution:
To reset the Identity column value we have a command in sql

USE Databasename
GO
DBCC CHECKIDENT ('schema.tablename' , RESEED, 0)
GO


On execution of this command successfully the below message is generated

Checking identity information: current identity value '0', current column value '0'.
DBCC execution completed.