Posts

Showing posts with the label sql server

SQL Statements

--1) Reseed Indentity column --drop table TABLE_NAME if  exists (select * from sys.objects where name='TABLE_NAME') drop table TABLE_NAME create table TABLE_NAME (ID int primary key identity (1,1),Increment int ) insert into TABLE_NAME (Increment ) values(1) insert into TABLE_NAME (Increment ) values(1) insert into TABLE_NAME (Increment ) values(1) insert into TABLE_NAME (Increment ) values(1) select 'Max of id is ' ,max(id) from TABLE_NAME delete from TABLE_NAME select 'Max of id after delete  ', isnull(max(id),0) from TABLE_NAME insert into TABLE_NAME (Increment ) values(1) insert into TABLE_NAME (Increment ) values(1) insert into TABLE_NAME (Increment ) values(1) insert into TABLE_NAME (Increment ) values(1) select 'Max of id after delete  insert', max(id) from TABLE_NAME --Reseed the Identity column with with one, so that the autoincremented delete  TABLE_NAME DBCC CHECKIDENT (TABLE_NAME, RESEED, 1) insert into TABLE_NA...

How to find out to which table the column name belongs to ?

How to find out to which table the column name belongs to ? Ans: SELECT TABLE_NAME=SYSOBJECTS.NAME, COLUMN_NAME=SYSCOLUMNS.NAME, DATATYPE=SYSTYPES.NAME, LENGTH=SYSCOLUMNS.LENGTH FROM SYSOBJECTS JOIN SYSCOLUMNS ON SYSOBJECTS.ID = SYSCOLUMNS.ID JOIN SYSTYPES ON SYSCOLUMNS.XTYPE=SYSTYPES.XTYPE WHERE SYSOBJECTS.XTYPE=’U’ AND SYSCOLUMNS.NAME LIKE (‘COLUMNAME2FIND%’) ORDER BY SYSOBJECTS.NAME,SYSCOLUMNS.COLID --keep posting