Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We can also find unused columns and table using following query. I tired to write cursor. Cursor will give you information aboout each column n each table.</p> <pre><code>declare @name varchar(200), @id bigint, @columnname varchar(500) declare @temptable table ( table_name varchar(500), Status bit ) declare @temp_column_name table ( table_name varchar(500), column_name varchar(500), Status bit ) declare find_table_dependency cursor for select name, id from sysobjects where xtype ='U' open find_table_dependency fetch find_table_dependency into @name, @id while @@fetch_Status = 0 begin if exists(select top 1 name from sysobjects where id in (select id from syscomments where text like '%'+@name +'%')) insert into @temptable select @name, 1 else insert into @temptable select @name, 0 declare find_column_dependency cursor for select name from syscolumns where id = @id open find_column_dependency fetch find_column_dependency into @columnname while @@fetch_Status = 0 begin if exists(select top 1 name from sysobjects where id in (select id from syscomments where text like '%'+@columnname +'%')) insert into @temp_column_name select @name,@columnname, 1 else insert into @temp_column_name select @name,@columnname, 0 fetch find_column_dependency into @columnname end close find_column_dependency deallocate find_column_dependency fetch find_table_dependency into @name, @id end close find_table_dependency deallocate find_table_dependency select * from @temptable select * from @temp_column_name </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload