How to Rename or Drop User-Defined Database in SQL Programming

Renaming a User-Defined Database

After creating a user-defined database in SQL server, programmer can rename a database whenever required. Only a system administrator or the database owner can rename a database. The sp_renamedb stored procedure is used to rename a database. The syntax of the sp_renamedb statement is:

Sp_renamedb old_database_name, new_database_name

  • old_database_name is the current name of the database
  • new_database_name is the new name of the database 
For example, the following SQL query renames the Personnel database.
Sp_renamedb Personnel Personnel1

Dropping a User-Defined Database

Programmer can delete a database when it is no longer required. This causes all the database files and data to be deleted. Only the users with sysadmin role and the database owner have the permissions to delete a database. The syntax of the DROP DATABASE statement is:

DROP DATABASE database_name
Database_name is the name of the database.

The following SQL query deletes the Employee database:

Programmer cannot delete a system-defined database. Programmer can rename or delete a database using the Object Explorer window by right-clicking the Databases folder and selecting the Rename or Delete option from the shortcut menu.
Create User-Defined Database 


Popular posts from this blog

difference between structure and union in C Language

Difference between Linear search and Binary Search in c language

Difference between static and dynamic websites