SQL Server Accidental DBA

Restore transaction log SQL Server

Backup and Restore are the common tasks that a DBA needs to perform almost daily. In this blog I’ll talk about how to restore a transaction log in SQL Server. A …
Read More »

Restore database SQL Server command with replace

Restore database SQL Server command with replace option is used when we need overwrite an existing database from a backup. The T-SQL command for same is shown below. RESTORE DATABASE [AdventureWorks2014] …
Read More »

T-SQL script to delete files

Many a times need arises to access/modify windows folder structures from SQL server. Though SQL Server is not meant for this purpose, however here is a T-SQL script to delete files …
Read More »

Restore transaction log point in time

This is an awesome feature where in one can restore transaction log point in time. A database can be restored to a specified using STOPAT option in restore command. Let’s look …
Read More »

T-SQL script to find the cd key from registry of SQL Server

Many a times we need to find details about SQL server installation when inheriting a new environment or a setup. One way to figure it out is by reading a registry. …
Read More »

T-SQL script to find column in database

Many a times we need to find all tables having a particular column in a database. Here is a T-SQL script to find column in database. SELECT DB_NAME(DB_ID()) As DatabaseName, OBJECT_SCHEMA_NAME(objects.object_id,db_id()) …
Read More »

T-SQL find constraints on table

Many a times need arises to find all constraints on a table. A common use case is when dropping columns from a table we need to know the dependent objects so …
Read More »

Simple cursor in SQL Server to insert records

This blog briefs about using a simple cursor in SQL Server to insert records. This is not a real world complex example; however it will help you to understand to use …
Read More »

T-SQL script to find duplicates

A common task for DBAs/Developers is to find duplicates in tables to avoid redundancy and storage misuse. Here is a T-SQL script to find duplicates. Create table tblDup(Sno int identity, Col1 …
Read More »

Find dependencies of stored procedure in SQL Server

Many a times need arises to find objects a stored procedure depends on. The blogs describes a way to find dependencies of stored procedure in SQL server. The below query creates …
Read More »

Find dependencies of a table in SQL Server

Many a times need arises to find all objects table depends on or is being referred. This blog will help you to find dependencies of a table in SQL Server. This …
Read More »

Start SQL Server in single user mode command prompt

Start SQL Server in single user mode command prompt is a must know task for any  SQL server DBA. This can be either done via GUI by setting the startup parameters for …
Read More »

Find stored procedure related to column in database in SQL Server

Here is quick query to find stored procedure related to column in database. This comes handy when you have to alter/remove a particular column from a table and you need to …
Read More »

Find stored procedure related to table in database in SQL Server

Many a times need arises to find all stored procedures related to a table in the database. The below queries come handy then. -- Query 1 SELECT DISTINCT objects.name, objects.type, comments.text …
Read More »

Truncate log file in SQL Server

Every now and then questions come up forums asking about how to truncate log file in SQL Server.  Truncating a transaction log file means clearing out space in the log file.  …
Read More »

SQL function - convert list to table

Here is quick SQL function to convert list to table. -- sql function to convert list to table CREATE FUNCTION fn_listtotable ( @list nvarchar(max), @delimeter nvarchar(100) ) RETURNS @split TABLE ( …
Read More »

Create comma delimited list in SQL Server

Many a times need arises to create comma delimited list in SQL Server. This can be done using the DOR XML PATH feature of SQL Server. The FOR XML PATH generates …
Read More »

Re indexing database tables in SQL Server

Re indexing database tables in SQL server is a very wide topic. Ideally, we have database maintenance tasks scheduled to run during maintenance window to rebuild indexes along with other maintenance …
Read More »

SQL Server error 15023 User already exists in current database

The SQL Server error 15023 User already exists in current database occurs when a databases is restored from another instance. The database users aren’t mapped to the corresponding logins at the …
Read More »

Restore database backup using SQL script

Here is a way to restore database backup using SQL script. The first step is to get the logical file names contained in the backup device. -- get file names from …
Read More »

« Newer Entries
   

One Comment on “SQL Server Accidental DBA”

Leave a Reply

Your email address will not be published.