Posts

Showing posts from July, 2018

Restore of database 'DataBase_Name' failed. (Microsoft.SqlServer.Management.RelationalEngineTasks)

TITLE: Microsoft SQL Server Management Studio ------------------------------ Restore of database 'DataBase_Name' failed. (Microsoft.SqlServer.Management.RelationalEngineTasks) ------------------------------ ADDITIONAL INFORMATION: System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the database is in use. (Microsoft.SqlServer.SmoExtended) For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=12.0.2000.8+((SQL14_RTM).140220-1752)&LinkId=20476 ------------------------------ BUTTONS: OK ------------------------------ Procedure 1: 1. Right click Databases 2. Restore Database... 3. [General] Source from Device, select the bak file 4. [General] Change the Destination database name to a new name 5. [Files] Change mdf and ldf Restore As paths to a different, new path 6. [Options] (unnecessary on the other computer) Check Overwrite the existing database (WITH_REPLACE) 7. [Options] (unnecessary on the other computer) Chec

Rules for Database Coding

STORED PROCEDURES Ownership a)      The developer writing the Stored Procedure must provide his / her Full Name, Create Date, and brief Description of the Stored Procedure. This commented information should be the first part of the Stored Procedure. -- Author          : Author Name           -- Create date     : Date       -- Description     : Brief Description       SET Options b)      The Following options should be set in Each Stored Procedure, set ANSI_NULLS ON set QUOTED_IDENTIFIER ON SET NOCOUNT ON   Naming Conventions a)      Stored Procedure name should start with ‘usp’. The next alphabet after ‘usp’ should be CAPITAL and each recognizable word in the name of Stored Procedure should start with CAPITAL letter. For example ‘uspInsertProcedure’   b)      INPUT parameters of Stored Procedure should start with ‘@p’ and end with ‘_IN’. For Example, @pInputVariable_IN.   The next alphabet after ‘@p’ should be CAPITAL and each recognizable word in the name of varia

worst performance query in sql server

SELECT        MIN ( query_text . statement_text ) AS [Query Text] ,     SUM ( query_text . total_worker_time ) / SUM ( query_text . execution_count ) AS [Avg CPU Time] ,        SUM ( query_text . total_elapsed_time )/ SUM ( query_text . execution_count ) AS [AVG Execution Time] ,        SUM ( total_physical_reads ) [Total Physical Reads] ,        SUM ( total_rows ) [Total Rows Returned] FROM     ( SELECT               EQS .*,               SUBSTRING ( ST . text , ( EQS . statement_start_offset / 2 ) + 1 ,               (( CASE statement_end_offset                      WHEN - 1 THEN DATALENGTH ( ST . text )                      ELSE EQS . statement_end_offset END             - EQS . statement_start_offset )/ 2 ) + 1 ) AS statement_text      FROM sys . dm_exec_query_stats AS EQS      CROSS APPLY sys . dm_exec_sql_text ( EQS . sql_handle ) as ST ) as query_text GROUP BY query_text . query_hash ORDER BY [Avg CPU Time] DESC ;

Query to find SQLServer Database File Growth Details

select DB_Name ( database_id ) as DB , file_id as FileID_ONServer , physical_name , type_desc , case when is_percent_growth = '1' then 0 else   convert ( decimal ( 12 , 1 ),(( growth * 8 )/ 1024.00 )) end as growth_in_MB , case when max_size = '-1' then max_size else convert ( decimal ( 38 , 2 ),(( max_size / 1024.00 )* 8 )) end as maxsize_in_mb , case when is_percent_growth = '1' then growth else   0 end as growth_in_Percent , is_percent_growth from sys . master_files ;