Creating, Altering, & Deleting Database in SQL
A database is basically a data structure where all the records are stored in an organized manner. Those records can be retrieved, updated, or deleted using a desktop application or a server-side scripting language like PHP, ASP.net etc.
To create a database in SQL, we make use of Create statement. Sample code is given below.
Create Database MyDatabase
To make changes in database in SQL, we make use of Alter statement. Sample code is given below to change the database name.
Create Database MyDatabase Modify Name = NewDatabase
To delete database in SQL, we make use of Drop statement. Sample code is given below.
Drop Database MyDatabase
If multiple users are connected to a database at the same time, then above given Drop statement will throw an error while dropping database. In such scenario, we need to change our database from multi user mode to single user mode by rolling back all incomplete transactions. Sample code is given below:
Alter Database MyDatabase Set SINGLE_USER With Rollback Immediate