Home

Creating a Database

 

Introduction

To create a database in SQL, use the following formula:

CREATE DATABASE DatabaseName

Here is an example:

CREATE DATABASE BethesdaCarRental;

If you want the name of the database to be in different words, include them in square brackets. Here is an example:

CREATE DATABASE [Bethesda Car Rental];

If you want the name of the database to be in different words, include them in square brackets.

To start from a sample code, open an empty Query window and display the Template Explorer. From the Template Explorer, expand Database. Drag Create Database and drop it in the Query window:

-- =============================================
-- Create database template
-- =============================================
USE master
GO

-- Drop the database if it already exists
IF  EXISTS (
	SELECT name 
		FROM sys.databases 
		WHERE name = N'<Database_Name, sysname, Database_Name>'
)

CREATE DATABASE <Database_Name, sysname, Database_Name>
GO

To visually create a database, open Microsoft SQL Server Management Studio. In the Object Explorer, expand the server name followed by the Databases node. Right-click Databases and click New Database...

New Database

In the Name text box, type the desired name of the new database. Here is an example:

Then specify the other properties of the new database:

Initial Size


Home Copyright © 2007-2011 FunctionX.com, Inc.