How to rename and drop a Database form SQL Server using command and Management Studio?

Asked 14-Sep-2021
Viewed 472 times

0

How to rename and drop a Database from SQL Server using command and Management Studio?


1 Answer


0

Rename Database in SQL Server-

    There are two ways to change the name of a Database in SQL Server.

1-  By using SQL sp_renamedb Command-

    Syntax-         EXEC sp_renamedb 'oldDbName' , 'newDbName' ;

Example-     The following SQL statement is used to change the existing database name 'Employees' to 'EmployeeDetails' 

                            EXEC sp_renamedb 'Employees' , 'EmployeeDetails';

                                                How to rename and drop a Database form SQL Server using command and Management Studio?

2- By using SQL ALTER Command- 

syntax-                ALTER DATABASE oldDbName MODIFY NAME = newDbName ;

Example-     The following SQL statement is used  change the existing Database name 'EmployeeDetails' to 'Employees'

                                          alter database EmployeeDetails modify name = Employees; 
                                        How to rename and drop a Database form SQL Server using command and Management Studio?


Delete Database in SQL Server-

Drop or Delete the Database using SQL Command -

        Syntax-             DROP DATABASE databaseName;

Example-                The following SQL statement is used to delete the database.

                                                            drop database DemoDB;

Delete Database by using SQL Server Management Studio-

    To delete the Database from you SQL Server Management Studio. follow the below steps

        Go To Object Explorer ---> Select Database you want to Delete ---> Right click on that Database name -----> Select 'Delete' option from Option Menu.

                                                    How to rename and drop a Database form SQL Server using command and Management Studio?

After click on Delete option a window open on your screen as like below. In which you click on OK 

                                                   How to rename and drop a Database form SQL Server using command and Management Studio?