Different strategies for removing duplicate records in SQL Server
--A more simplified and faster example
WITH CTE AS
(
SELECT ROW_NUMBER() OVER
(PARTITION BY [FirstName], [LastName], [Address]
Order BY [FirstName] DESC, [LastName] DESC, [Address] DESC )
AS RowNumber,
[FirstName], [LastName], [Address]
FROM Employee tbl )
DELETE FROM CTE Where RowNumber > 1
GO
SELECT * FROM Employee
GO
четверг, 18 февраля 2010 г.
понедельник, 1 февраля 2010 г.
SQL-полезное (Усечение LOG файла)
SQL SERVER – Shrinking Truncate Log File – Log Full
Sometime, it looks impossible to shrink the Truncated Log file. Following code always shrinks the Truncated Log File to minimum size possible.
USE DatabaseName
GO
DBCC SHRINKFILE(<TransactionLogName>, 1)
BACKUP LOG <DatabaseName> WITH TRUNCATE_ONLY
DBCC SHRINKFILE(<TransactionLogName>, 1)
GO
====================================================================
Another best way to truncate log file with out taking transactional backup would be,
1. Change recovery model from Full to Simple ( using Interfaces) and then change it back to Full. By doing this your log file will be truncated.
2. Run DBCC ShrinkFile ( ‘LogfileName’ , 1)
By doing this, you will definitely loose your transactional log data that was stored in log file. But this will truncate Log file with out taking any backup.
USE temp;
GO
– Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE temp
SET RECOVERY SIMPLE;
GO
– Shrink the truncated log file to 100 MB.
DBCC SHRINKFILE (temp_Log, 100);
GO
– Reset the database recovery model.
ALTER DATABASE temp
SET RECOVERY FULL;
GO
Sometime, it looks impossible to shrink the Truncated Log file. Following code always shrinks the Truncated Log File to minimum size possible.
USE DatabaseName
GO
DBCC SHRINKFILE(<TransactionLogName>, 1)
BACKUP LOG <DatabaseName> WITH TRUNCATE_ONLY
DBCC SHRINKFILE(<TransactionLogName>, 1)
GO
====================================================================
Another best way to truncate log file with out taking transactional backup would be,
1. Change recovery model from Full to Simple ( using Interfaces) and then change it back to Full. By doing this your log file will be truncated.
2. Run DBCC ShrinkFile ( ‘LogfileName’ , 1)
By doing this, you will definitely loose your transactional log data that was stored in log file. But this will truncate Log file with out taking any backup.
USE temp;
GO
– Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE temp
SET RECOVERY SIMPLE;
GO
– Shrink the truncated log file to 100 MB.
DBCC SHRINKFILE (temp_Log, 100);
GO
– Reset the database recovery model.
ALTER DATABASE temp
SET RECOVERY FULL;
GO
Подписаться на:
Сообщения (Atom)