SQL Server Accidental DBA

SQL Server Restore Filelistonly from disk

Many a times we need to get the details of what is in the database backup device before we do a database restore for e.g. if we have to move the …
Read More »

SQL Server restore master database

Restore master database is a must know task for any DBA. Master database is one of the key SQL Server database and should be a part of backup/maintenance plan. In case …
Read More »

SQL Server restore database with move example

A common task for a DBA is to restore a database to a new location. The script for the same is given below USE [master] GO RESTORE DATABASE [AdventureWorks] FROM DISK …
Read More »

Restore SQL Server database from bak file command line

Here is a script to restore SQL Server database from bak file command line. This is done via SQLCMD through command line. The first thing is to open up the command …
Read More »

Function to Convert Text String to Proper Case in SQL Server

Many a times need arises to convert a string into proper case specially the names. Let’s have a look at a SQL Server function to convert text string to proper case. …
Read More »

Function to Convert String to Date in SQL Server

The SQL Server has inbuilt function to convert string to date. It can be done using CAST/CONVERT as shown below DECLARE @stringdate varchar(100), @cast_dt datetime, @conver_dt datetime SET @stringdate='09/25/2014' SET @cast_dt=CAST(@stringdate …
Read More »

Restore database backup to different name in SQL Server

A common day to day task for a DBA is to backup/restore databases for testing/development/production purposes. In this blog we’ll see how to restore database backup to different name. Let’s first …
Read More »

SQL Server Find largest tables

Here is a query to SQL Server find largest tables in a database. It’s very important for a DBA to monitor table size over time to foresee storage requirement/performance issues. The …
Read More »

SQL Server shrinking transaction log file

Every now and then there is a question on forum mentioning that transaction log file has grown large, how to shrink it. This blog talks about SQL Server shrinking transaction log …
Read More »

How to kill multiple sessions in SQL Server

In my last blog I talked about how to kill a session in SQL Server. In this blog I will talk about how to kill multiple sessions in SQL Server. The …
Read More »

How to kill all sessions in SQL Server

In my previous two blogs, I talked about how kill a session in SQL Server and how to kill multiple sessions in SQL Server. In this blog I will talk about …
Read More »

How to kill a thread in SQL Server

In my last three blogs I talked about how to kill a session in SQL Server, how to kill multiple sessions in SQL server and how to kill all sessions in …
Read More »

How to kill a session in SQL Server

Sometime or the other we do feel the need to forcefully kill a session in SQL Server. It’s not recommended and shouldn’t be run on production unless otherwise absolutely required. However, …
Read More »

SQL query to get row size in SQL Server

Below is a SQL query to find row size. The query uses DATALENGTH function, which returns the number of bytes used to represent a column data. A row may consist of …
Read More »

SQL Query to find table size in SQL Server

Below is a SQL query to find table size in SQL Server. The calculation is based on SQL Query to find row size SQL Server blog (give the link of the …
Read More »

Simple cursor in SQL server to update rows

The blog explains a simple cursor in SQL Server to update rows. This is just for explanation, the update query can be written without using cursor too. The T-SQL is given …
Read More »

Simple cursor in SQL Server

A cursor is a way to iterate each row one by one in a SQL Server table. Although, T-SQL is a set based language however, many a times need arises to …
Read More »

Query to display foreign key relationships in SQL Server

Below is a query to display foreign key relationships in a database. SELECT fks.NAME AS ForeignKey, fks.is_disabled, Schema_name(fks.schema_id) + '.' + Object_name(fks.parent_object_id) AS TableName, Col_name(fkcs.parent_object_id, fkcs.parent_column_id) AS ColumnName, (SELECT Schema_name(schema_id) + …
Read More »

Restore transaction log with norecovery in SQL Server

Restore transaction log with NORECOVERY option is used when restoring multiple transaction log. Consider a backup strategy where in full backup is being taken once a week and transaction log backup …
Read More »

T-SQL Script to backup all databases

Database backup is a must know task for a DBA. In this blog we’ll look at T-SQL script to backup all databases at once. The logic is to iterate through all …
Read More »

« Newer EntriesOlder Entries »
   

One Comment on “SQL Server Accidental DBA”

Leave a Reply

Your email address will not be published.