SQL Server Tutorial
'create database' statement is used to create a database in SQL Server.
CREATE DATABASE <DATABASE NAME>;
CREATE DATABASE learn_db;Output:
Command(s) completed successfully.
We need admin privilege to create a database in SQL Server, Check the privileges enable for logged in user before creating any databases.
SELECT name FROM master.dbo.sysdatabasesOutput:
EXEC sp_databasesOutput:
SELECT [name] FROM master.dbo.sysdatabases WHERE dbid > 4We can also add condition like below to filter system databases.
select name from sys.databases WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb');Output:
DROP DATABASE <DATABASE NAME>;
DROP DATABASE learn_db1Output:
Command(s) completed successfully.When you drop the database which is also active database, then you will get below error.
Cannot drop the database 'learn_db', because it does not exist or you do not have permission.Change the active database as master or other than this database to drop it.
SQL Server Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page