mssql – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Sat, 07 Aug 2021 16:57:23 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 How to Backup SQL Server Database https://tecadmin.net/backup-sql-server-database/ https://tecadmin.net/backup-sql-server-database/#respond Mon, 28 Jun 2021 02:53:50 +0000 https://tecadmin.net/?p=26293 SQL Server is a relational database management system developed by Microsoft. It provides a powerful graphical interface called SQL Server Management Studio (SSMS), which provides all the features to manage your databases. Also provides options to backup and restore the database using graphical interfaces. Also, we can execute the T-SQL statement through SSMS to take [...]

The post How to Backup SQL Server Database appeared first on TecAdmin.

]]>
SQL Server is a relational database management system developed by Microsoft. It provides a powerful graphical interface called SQL Server Management Studio (SSMS), which provides all the features to manage your databases. Also provides options to backup and restore the database using graphical interfaces. Also, we can execute the T-SQL statement through SSMS to take a backup of the database.

How to Backup SQL Server Database

We can backup the SQL Serer database either with the T-SQL statements or we can use the SSMS wizard process to take full, differential, or transactional backup of the database.

Use one of the below options to backup the SQL Server database:

1. Backup Database using T-SQL

Launch SQL Server Management Studio and connect to the database server. Now open a query window and execute the following statement to back up the database in your local drive.

BACKUP DATABSAE [Test_db] TO DISK = 'D:\backup\Test_db.bak'
Go

Here Test_db is the database name and D:\backup\Test_db.bak is the backup file name with full path.

T-SQL Statement to Backup SQL Server Database

The above screenshot shows a successful database backup in the SQL server using a T-SQL statement. The next option will help you to backup the SQL Server database with a graphical interface.

2. Backup Database using SSMS

SQL Server Management Studio provides an option to backup SQL Server databases manually. To back up a SQL server database follow the below steps.

  1. Launch Management Studio and Connect to SQL Server
  2. Under databases, Select your database to backup
  3. Right-click on database and navigate to >> Tasks >> Backup

    Backup SQL Server Database - Step1

  4. Under the Source option, Correct databse is selected in dropdownlist. The backup type is set to Full.
  5. Under the Destination section, Remove any entry that already exists by clicking the remove button available on the right side. Then Click Add button to provide the correct backup path with filename.
  6. See the below screenshot, taking a full database backup of “Test_db” at path D:\backup\Test_db.bak.

    Backup SQL Server Database - Step2

  7. Once the backup completed successfully, you will see a message like below.

    Backup SQL Server Database Completed

Conclusion

In this tutorial, you have learned two methods to backup a SQL Server database. Next, you may like our tutorial to restore SQL Server database with T-SQL and SQL Server Management Studio

The post How to Backup SQL Server Database appeared first on TecAdmin.

]]>
https://tecadmin.net/backup-sql-server-database/feed/ 0
How to Rename a Column in SQL Server https://tecadmin.net/rename-column-name-in-sql-server-database/ https://tecadmin.net/rename-column-name-in-sql-server-database/#respond Sun, 16 Jun 2019 03:33:23 +0000 https://tecadmin.net/?p=18343 Database design is the organization of data. A good database design makes it successful. Its recommended to follow a good pattern for the table names and their columns. In some cases, you may be required to rename a column name of the table to maintain a proper architecture and naming pattern. The sp_rename stored procedure [...]

The post How to Rename a Column in SQL Server appeared first on TecAdmin.

]]>
Database design is the organization of data. A good database design makes it successful. Its recommended to follow a good pattern for the table names and their columns. In some cases, you may be required to rename a column name of the table to maintain a proper architecture and naming pattern. The sp_rename stored procedure is used to rename a column name in a table in MSSQL server database.

Syntax:

The syntax of the sp_rename stored procedure is:

sp_rename 'TableName.[OldColumnName]' , '[NewColumnName]', 'COLUMN'
Caution: Changing any part of an object name could break scripts and stored procedures. Make sure to update all the required scripts and stored procedures with updated names.

Rename a Column in SQL Server

For example, I have a table named Accounts in the MSSQL server database. This table contains a column named “cust_id”. For some reason, we need to rename this column to “customer_id”. See below screenshot:

Open query windows and execute the following query. Here Test_dbis the database name.

USE Test_db
GO

sp_rename 'Accounts.cust_id', 'customer_id' , 'COLUMN'
GO 

This may show you a warning message with the result, But this will rename the column name successfully. Checked the table structure again, and I found that the column is updated as required.

Rename table column in SQL Server

Conclusion

This tutorial helped you to rename a table column name in the SQL Server database.

The post How to Rename a Column in SQL Server appeared first on TecAdmin.

]]>
https://tecadmin.net/rename-column-name-in-sql-server-database/feed/ 0
FIXED MSSQL Error 3154 – The backup set holds a backup of a database other than the existing database https://tecadmin.net/fixed-mssql-error-3154-the-backup-set-holds-a-backup-of-a-database/ https://tecadmin.net/fixed-mssql-error-3154-the-backup-set-holds-a-backup-of-a-database/#respond Mon, 15 Aug 2016 11:54:24 +0000 https://tecadmin.net/?p=10881 Using SQL Query Window: Use WITH REPLACE option with the RESTORE command on MSSQL query window. Change database name and backup file location as per your setup. USE MASTER GO RESTORE DATABASE MyDB FROM DISK = 'C:\Backups\MyDB_15082016.bak' WITH REPLACE GO

The post FIXED MSSQL Error 3154 – The backup set holds a backup of a database other than the existing database appeared first on TecAdmin.

]]>
Using SQL Query Window:

Use WITH REPLACE option with the RESTORE command on MSSQL query window. Change database name and backup file location as per your setup.

USE MASTER
GO

RESTORE DATABASE  MyDB
FROM DISK = 'C:\Backups\MyDB_15082016.bak'
WITH REPLACE
GO

The post FIXED MSSQL Error 3154 – The backup set holds a backup of a database other than the existing database appeared first on TecAdmin.

]]>
https://tecadmin.net/fixed-mssql-error-3154-the-backup-set-holds-a-backup-of-a-database/feed/ 0
How To Create ASPState Database in SQL Server https://tecadmin.net/how-to-create-aspstate-database-in-sql-server/ https://tecadmin.net/how-to-create-aspstate-database-in-sql-server/#comments Wed, 03 Dec 2014 03:50:45 +0000 https://tecadmin.net/?p=6727 The ASPStage (ASP.NET Session State) provides you the option to store website session data to the SQL server database. This is a useful option with load balancing, where application deployment is on multiple servers. This tutorial will help you to create an ASPState database in SQL server with the command line. Prerequsities You must have [...]

The post How To Create ASPState Database in SQL Server appeared first on TecAdmin.

]]>
The ASPStage (ASP.NET Session State) provides you the option to store website session data to the SQL server database. This is a useful option with load balancing, where application deployment is on multiple servers. This tutorial will help you to create an ASPState database in SQL server with the command line.

Prerequsities

You must have installed the .net framework on your system to complete this task.

Create ASPState Database

After installing the .net framework on your system, open the windows command prompt and navigate to the framework installation directory as per your installed version of the .net framework and system architecture.

Syntax:

aspnet_regsql.exe -ssadd -sstype p -S {SQL Instance} -U {Username} -P {Password}

Implementation:

Navigate to the .net framework directory as followings:

c:\> cd "%windir%\Microsoft.NET\Framework64\v4.0.30319"

Directory path may be changed as per your installation like below.

.NET Framework 2.0/3.0/3.5 (32-bit): %windir%\Microsoft.NET\Framework\v2.0.50727
.NET Framework 2.0/3.0/3.5 (64-bit): %windir%\Microsoft.NET\Framework64\v2.0.50727
.NET Framework version 4.x (32-bit): %windir%\Microsoft.NET\Framework\v4.0.30319
.NET Framework version 4.x (64-bit): %windir%\Microsoft.NET\Framework64\v4.0.30319

Now execute following command to finally create database named ASPState in SQL server defined instance. As per below command DB1SQLEXPRESS is my SQL instance.

aspnet_regsql.exe -ssadd -sstype p -S DB1SQLEXPRESS -U sa -P myPassword

On successful execution of the above command, you will get output like below.

Microsoft (R) ASP.NET SQL Registration Tool version 4.0.30319.33440
Administrative utility to install and uninstall ASP.NET features on a SQL server.
Copyright (C) Microsoft Corporation. All rights reserved.

Start adding session state.
.........................
Finished.

The post How To Create ASPState Database in SQL Server appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-create-aspstate-database-in-sql-server/feed/ 2
How to Shrink SQL Server Transaction Log Files using DBCC SHRINKFILE https://tecadmin.net/shrink-sql-server-transaction-log-files-dbcc-shrinkfile/ https://tecadmin.net/shrink-sql-server-transaction-log-files-dbcc-shrinkfile/#comments Sat, 02 Mar 2013 12:58:08 +0000 https://tecadmin.net/?p=369 Sometimes SQL Server logs files acquire a large space on the disk. In that case, we need to reduce the size of the log file to claim some space. But truncating or reducing database log file in SQL Server 2008 can be quite difficult. It also has its own issues. This article contains a set [...]

The post How to Shrink SQL Server Transaction Log Files using DBCC SHRINKFILE appeared first on TecAdmin.

]]>
Sometimes SQL Server logs files acquire a large space on the disk. In that case, we need to reduce the size of the log file to claim some space. But truncating or reducing database log file in SQL Server 2008 can be quite difficult. It also has its own issues.

This article contains a set of commands to Shrink Log Files of SQL Server database.

Generally this command is I prefer to take a backup of the database before executing below command for a safer side

Shrink SQL Server Transaction Log Files

First of all, check the actual name of log files stored in SQL server records using the following SQL query. Execute these queries in using SQL Server management studio query browser.

USE DATABASE_NAME;
GO

SELECT FILE_NAME(2);
GO

Now, use the DBCC SHRINKFILE SQL command to shrink log files. The database must be running in SIMPLE recovery mode. Open the query windows in SQL Server management studio and run the following command. You

Make sure to change DATABASE_NAME with actual database name and LOG_FILE_NAME with log file name found in the above step. The below example query will shrink the log file to 1000MB.

USE DATABASE_NAME;
GO

ALTER DATABASE DATABASE_NAME
SET RECOVERY SIMPLE;
GO  

DBCC SHRINKFILE (LOG_FILE_NAME, 1000);
GO  

ALTER DATABASE DATABASE_NAME
SET RECOVERY FULL;
GO  

All done. Now check the size of the log files, I hope you will get the expected results.

The post How to Shrink SQL Server Transaction Log Files using DBCC SHRINKFILE appeared first on TecAdmin.

]]>
https://tecadmin.net/shrink-sql-server-transaction-log-files-dbcc-shrinkfile/feed/ 1