–rename columne
sp_RENAME ‘YourTableName.ColumnName’ , ‘UpdatedColumnName’
–find column exists or not
if Exists(select * from sys.columns where Name = N’columnName’
and Object_ID = Object_ID(N’tableName’))
begin
– Column Exists
end
–Find tables which does not have pk
Select [name] as “Table Name without PK”
from SysObjects where xtype=’U’ and
id not in
(
Select parent_obj from SysObjects where xtype=’PK’
) order by [name]
–Find tables which have 0 rows
SELECT OBJECT_NAME(OBJECT_ID) TableName, st.row_count
FROM sys.dm_db_partition_stats st
WHERE index_id < 2
and row_count = 0
ORDER BY OBJECT_NAME(OBJECT_ID) DESC
--find number of columns in table
select count(1) from syscolumns SC,Sysobjects SO
where
sc.id =so.id
and so.name = ‘tbl_Admin_City_M’
sp_RENAME ‘YourTableName.ColumnName’ , ‘UpdatedColumnName’
–find column exists or not
if Exists(select * from sys.columns where Name = N’columnName’
and Object_ID = Object_ID(N’tableName’))
begin
– Column Exists
end
–Find tables which does not have pk
Select [name] as “Table Name without PK”
from SysObjects where xtype=’U’ and
id not in
(
Select parent_obj from SysObjects where xtype=’PK’
) order by [name]
–Find tables which have 0 rows
SELECT OBJECT_NAME(OBJECT_ID) TableName, st.row_count
FROM sys.dm_db_partition_stats st
WHERE index_id < 2
and row_count = 0
ORDER BY OBJECT_NAME(OBJECT_ID) DESC
--find number of columns in table
select count(1) from syscolumns SC,Sysobjects SO
where
sc.id =so.id
and so.name = ‘tbl_Admin_City_M’
No comments:
Post a Comment