SQLforGeeks
  • Home
  • SQL
  • SQL Tutorial
  • SQL Syntax
  • Our Services
Contact
  1. SQL
  2. Restore database

Text copied!

« Previous
Next »

Restore database

Dec. 7, 2022, 7:24 p.m. under SQL

  • Hi! You should check Download database post first.

    Restoring an SQL database involves taking a backup of the database, and then restoring it into a SQL Server instance.

    There are several methods to restore SQL database, including using graphical user interface (GUI) or Transact-SQL (T-SQL).

    To restore [AdventureWorks2019] database, You will need to download and move "AdventureWorks2019.bak" file to default backup location of SQL instance. This SQL backup location varies depending on the installation location & version of SQL Server. For Instance, the default location for a default instance of SQL Server 2022 is as follows :

    C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\Backup
    Restore database
    Here's an example of how to restore database using T-SQL :

    1. Run below SQL commands in SSMS as given in below images :

    RESTORE FILELISTONLY FROM DISK = N'C:\Program Files\Microsoft SQL
    Server\MSSQL16.MSSQLSERVER\MSSQL\Backup\AdventureWorks2019.bak'
            
    Restore database
    USE [master]
    
    RESTORE DATABASE [AdventureWorks2019] 
    FROM  DISK = N'C:\Program Files\Microsoft SQL Server
    \MSSQL16.MSSQLSERVER\MSSQL\Backup\AdventureWorks2019.bak' 
    WITH  FILE = 1,  NOUNLOAD,  STATS = 5
            
    Restore database
    That's it! You have successfully restored [AdventureWorks2019] database using T-SQL.

    NOTE : You may have come across two different SQL database file types : "Raw Data" files and "Log" files. Raw data files are used to store the actual data of the database with ".mdf" file extension. While log files store a record of all changes made to the database with a ".ldf" file extension.

    Here's a step-by-step guide on how to restore SQL database using GUI :

    1. Open SQL Server Management Studio. In the "Connect to Server" window, select the Server type as "Database Engine" >> In the "Server name" field, enter the name of the server where SQL Server is installed >> In the "Authentication" field, as of now select "Windows Authentication" otherwise you can also select "SQL Server Authentication" and fill login name and password when/if any SQL user is created at the installation time or later >> Now click the "Connect" button to connect to the SQL Server instance.

    Restore database

    2. You have successfully connected to SQL Server. Next, In the Object Explorer, right-click on the "Databases folder" >> Select "Restore Database".

    Restore database Restore database

    3. In the "General" tab of the "Restore Database" window, select "Device" option >> Click on ellipsis ( three dots ) >> Click on the "OK" button.

    Restore database

    4. Change Backup media type option as "File" >> Click the "Add" button to browse for the backup file.

    Restore database

    5. Select the "AdventureWorks2019.bak" backup file or any other backup set that you want to restore from SQL Server backup location >> Click on the "OK" button.

    Restore database

    Keep clicking on the "OK" button until "restored successful" message appears.

    Restore database Restore database Restore database
    That's it! You have successfully restored [AdventureWorks2019] database using GUI.
    Restore database

    NOTE : In the "Files" tab, You may have come across two different SQL database file types : "Raw Data" files and "Log" files. Raw data files are used to store the actual data of the database with ".mdf" file extension. While log files store a record of all changes made to the database with a ".ldf" file extension.

    Restore database

    Frequently Asked Questions :

    How do I restore SQL database progress?

    Monitor the restoration process using progress indicators provided by your database management system.

    What does it mean to restore a database?

    Restoring a database means recovering a database to a previous state, typically by importing a backup file to replace the existing data.

    Which command is used to restore the database in SQL?

    The command used to restore a database in SQL can vary depending on the database management system being used, such as "RESTORE DATABASE" for SQL Server.

    How do I restore a SQL database?

    Restore a SQL database by executing the appropriate restore command for your database system, ensuring compatibility with backup files and monitoring the process for completion.
    Thank You! You should check Backup database post next.
    « Previous
    Next »
    RELATED :

    What is SQL

    What is T-SQL

    Difference between DBMS and Data Warehouse

    Download SQL Server

    Install SQL Server

    Download SQL Server Management Studio SSMS

    SQL Server Management Studio

    SQL Database

    Download database

    Backup database

    Attach database

    Detach database

    Create database

    Delete database

    Rename database

    Select database

    Database offline

    Database online

    SQL Commands

    SQL Tables

    Create table

    Truncate table

    Delete table

    Rename table

    Select table

    Alter table

    SQL Data Types

    SQL Comments

    SQL Constraints

    SQL Joins

    SQL inner join

    SQL left join

    SQL right join

    SQL full join

    SQL cross join

    SQL self join

    INSERT INTO SELECT statement

    INSERT INTO statement

    SQL Clauses

    SELECT clause

    FROM clause

    WHERE clause

    GROUP BY clause

    HAVING clause

    ORDER BY clause

    JOIN clause

    UNION clause

    UNION ALL clause

    TOP clause

    DISTINCT clause

    SQL Operators

    SQL Arithmetic operators

    SQL Comparison operators

    SQL Logical operators

    UNION operator

    UNION ALL operator

    INTERSECT operator

    EXCEPT operator

    LIKE operator

    NOT LIKE operator

    IN operator

    NOT IN operator

    IS NULL operator

    IS NOT NULL operator

    EXISTS operator

    NOT EXISTS operator

    BETWEEN operator

    NOT BETWEEN operator

    SQL Functions

    SQL Built-In functions

    CHARINDEX function

    DATEADD function

    CONCAT function

    LEN function

    REPLACE function

    SUBSTRING function

    CASE statement

    GETDATE function

    DATEPART function

    DATEDIFF function

    CAST function

    TRY_CAST function

    CONVERT function

    TRY_CONVERT function

    ISNULL function

    NULLIF function

    COALESCE function

    SQL Window functions

    ROW_NUMBER function

    RANK function

    DENSE_RANK function

    IIF function

    CHOOSE function

    SQL Store Procedure

    Store Procedure vs. Function

    SQL Subquery

    SQL Aliases

    Temp table

    SQL Error Handling

    SQL Variables

    SQL Views

    SQL Merge

    SQL CTE

    SQL WITH TIES

    Define Transaction in DBMS

    ACID properties in DBMS

    Types of Triggers in DBMS


    • Have Some Questions?
    logo

    Elevate your data experience with SQL excellence

    Quick Links
    •  Home
    •  SQL Tutorial
    •  SQL Syntax
    •  Our Services
    Our Services
    • Web Development
    • BI Development
    • Data Warehousing
    • Data Integration ETL


    Follow Us

    GST Registered: XXAXXXXXXXZX
    Mumbai, Maharashtra, India support@sqlforgeeks.com

    © 2025 Copyright™ | All Rights Reserved | Privacy Policy