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 “SELECT NAME FROM MASTER.SYS.DATABASES” 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 -