SqlScriptCheatSheet



Delete Duplicate rows
Delete from TableName where ColumnName IN ( Select ColumnName from TableName GROUP BY ColumnName HAVING ( COUNT(ColumnName) > 1 ) )
Reseed the Identity Column
DBCC CHECKIDENT (BPOLReceipts, RESEED, 50000)
Delete Records from the table within certain range
Delete from TableName where Id> 2439 and Id< 2485
Delete specific multiple records
delete from TableName where id in (1, 4, 6, 7)
Change a Column name of existing table:
ALTER TABLE table_name ADD column_name column_definition;
ALTER TABLE employees ADD last_name VARCHAR(50);

Change a column type of the existing table:

ALTER TABLE TableName ALTER COLUMN ColumnName numeric(20, 2)
Drop column from the table
ALTER TABLE TableName Drop column TableName ;
To create Update statement..Update values: To quickly set multiple update values. Copy the items to the excel spreadsheet, then add same items with @ sign to the next column. And use this formula
=D5 &"=" &H5
Changing the seed on existing table/ Resetting seed
DBCC CHECKIDENT ('tablename', RESEED,50000 ) GO

No comments:

Post a Comment