Creating, Altering, & Deleting Database in SQL

Creating, Altering, & Deleting Database in SQL
Rating: 5 - 1 Votes

Creating, Altering, & Deleting Database in SQL

sqlA 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.

 

To make changes in database in SQL, we make use of Alter statement.  Sample code is given below to change the database name.

 

To delete database in SQL, we make use of Drop statement.  Sample code is given below.

 

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: