MSSQL Create Database With SQL Statement
Posted by in SQL Server February 17, 2012 1 Comment

Just an example How to create a new database in Microsoft SQL Server by using SQL statement. Before creating, we need to check whether the database is already exited or not.

USE master
GO
 
---------------------
-- Create database --
---------------------
IF NOT EXISTS (SELECT * 
	   FROM   master..sysdatabases 
	   WHERE  name = N'your_database_name')
	BEGIN
		CREATE DATABASE your_database_name
	END
GO
MSSQL Create Database With SQL Statement

MSSQL Create Database With SQL Statement

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at hoan@4rapiddev.com
  • Quynhnguyenm83

    That’s so strange…it uses
    master..sysdatabases(two dots) not master.sysdatabases?