T-SQL – RESEED identity if the table has zero records

The below code reseeds identity value if the table has zero record count. –Temp tables to hold tablenames & recordcounts CREATE TABLE ##TableRowCounts([TableName] VARCHAR(128), [RowCount] INT) ; CREATE TABLE ##TableNoRowCounts(RN INT IDENTITY(1,1),[TableName] VARCHAR(128), [RowCount] INT) ; INSERT INTO ##TableRowCounts ([TableName], [RowCount])EXEC sp_MSforeachtable ‘SELECT ”?” [TableName], COUNT(*) [RowCount] FROM ?’ ; INSERT ##TableNoRowCountsSELECT [TableName], [RowCount] FROM…

Details

SQL Server – DBCC PAGE and DBCC IND

DBCC IND – used to know the page details of tables & indexes. syntax: DBCC IND ( {dbname}, {table_name},{index_id} ) Description of columns displayed from DBCC IND PageFID File ID of Page PagePID Page ID IAMFID,IAMPID File ID&Page ID -> IAM mapping ObjectID  object ID(Table) IndexID Clustered index (IndexID = 1),Non clustered index (IndexID = 2) PartitionNumber  Number of…

Details