Showing posts with label SQL Server. Show all posts
Showing posts with label SQL Server. Show all posts

Thursday, August 27, 2015

How to Get Rid of Standby/Read-Only/Warm-Standby on SQL Server

How to Get Rid of Standby/Read-Only/Warm-Standby on SQL Server

Here is a simple instruction for doing so:

USE master;
GO
ALTER DATABASE my_database_name SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
ALTER DATABASE my_database_name SET MULTI_USER WITH ROLLBACK IMMEDIATE;
GO
RESTORE DATABASE my_database_name WITH RECOVERY
GO
ALTER DATABASE my_database_name SET READ_WRITE



Thursday, September 25, 2008

DBREINDEX


A SQL Server database will execute queries (reports) faster by re-indexing its tables.

DBCC DBREINDEX re-builds indices for a table. DBCC DBREINDEX can rebuild all the indices for a table in one statement (much easier than running several DROP INDEX and CREATE INDEX sql statements and also DBCC DBREINDEX provides the advantage of getting more optimizations than individual DROP INDEX and CREATE INDEX sql statements).

NOTE: DBCC DBREINDEX cannot be used for system tables.The following script can be used to re-build the indices of a database:



-- This script re-builds the indices of a SQL Server database.
-- Author: G. R. Roosta
-- License: Free To Use (No Restriction)

USE database_name;
GO
DECLARE @TableName varchar(255)
DECLARE fabriclake CURSOR FOR
SELECT table_name
FROM information_schema.tables
WHERE table_type = 'base table'

OPEN fabriclake
FETCH NEXT FROM fabriclake INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
DBCC DBREINDEX(@TableName,' ',90)
FETCH NEXT FROM fabriclake INTO @TableName
END
CLOSE fabriclake
DEALLOCATE fabriclake

MODIFY LOGICAL NAME IN SQL SERVER

To modify the logical name of a data file or a log file in SQL Server, specify the logical file name you want to rename by using the Name parameter and then specify the new logical name for the file by using the NewName parameter. To rename the logical file, run the following T-SQL statement:

ALTER DATABASE database_name MODIFY FILE ( NAME = current_logical_name, NEWNAME = new_logical_name)