Basic SQL Commands on Database in SQL Server

Display Existing Databases

In “SQL Server”, to “Displays” the “List” of the “Already Existing Databases”, the Command “” is used.

Create a Database

To “Create” a “New Database”, the “CREATE DATABASE <database-name>” Command is used.

Trying to “Create” an “Already Existing Database”, an “Error” is displayed.

Verify If a Database Exists and Create If It Doesn’t

In “SQL Server”, to “Verify” if a “Given Database” “Exists”, and, if it “Doesn’t Exist”, “Only” then to “Create” the “Given Database”, the following approach is used -

Use a Database

To “Go Inside” a “Particular Database”, or “Start Using” a “Particular Database”, the “USE <database-name> Command is used.

Once that “Particular Database” is “Connected”, whatever “Operations” are “Performed” from that time, will be “Done Inside” that “Particular Database”.

How to Know the Current Database in Use

In “SQL Server”, to “Know” which “Database” is “Currently in Use”, the Command “SELECT DB_NAME ()” is used.

Drop a Database

To “Drop”, or “Delete” an “Already Existing Database”, the “DROP DATABASE <database-name>” Command is used.

In “SQL Server”, To “Verify” if a “Given Database” “Exists”, and, if it “Exists”, “Only” then to “Drop” the “Given Database”, the following approach is used -

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Oindrila Chakraborty

I have 10+ experience in IT industry. I love to learn about the data and work with data. I am happy to share my knowledge with all. Hope this will be of help.