To add an identity field when a table has no identity field use
Select Row_Number() over (order by [any Column name]) as Id,[Col1],col2,..... from [Table Name]
Wednesday, January 21, 2009
Tuesday, January 20, 2009
Find and Clear Duplicates from sql table
To Find duplicates:
select [col1],[col2] from [TableName] where [condition]
group by [col1],[col2],[col3],[col4] having count(*) > 1
select [
group by [col1],[col2],[col3],[col4] having count(*) > 1
Drop all the tables from a database
To delete all the tables from a database:
Select 'drop table ' + Object_name(object_id) from sys.objects where type = 'U'
(or)
EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"
To Delete All Records from a table:
Select 'delete from ' + Object_name(object_id) from sys.objects where type = 'U'
Select 'drop table ' + Object_name(object_id) from sys.objects where type = 'U'
(or)
EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"
To Delete All Records from a table:
Select 'delete from ' + Object_name(object_id) from sys.objects where type = 'U'
Subscribe to:
Posts (Atom)