Quackit Logo

FREE Hosting!

With every domain name you register with ZappyHost, you get FREE hosting.

$1.99 Domain Names

With every new non-domain purchase thru ZappyHost, you get a domain name for only $1.99.

SQL Create Database

Print Version

You can create a database using the CREATE DATABASE command.

SQL syntax

CREATE DATABASE database_name

Example Code

This statement creates a database called "Payroll". Because no arguments have been specified, the database data files and transaction logs will be created automatically in the default location.

CREATE DATABASE Payroll

Adding Arguments

There are a number of optional arguments that you can supply with the CREATE DATABASE command. You should check your database system's documentation for the specific arguments supported and their usage, but here's an example of supplying arguments when creating a database using Microsoft's SQL Server.

Example Code

In this example, we are supplying the name and location of the database's data file and transaction log. We are also specifying the initial size of these files (with the SIZE argument), the maximum size it can grow to (with the MAXSIZE argument) and the growth increment of each file (using the FILEGROWTH) argument.

USE master
GO
CREATE DATABASE Payroll
ON
( NAME = Payroll_dat,
   FILENAME = 'c:\program files\microsoft sql server\mssql\data\payrolldat.mdf',
   SIZE = 20MB,
   MAXSIZE = 70MB,
   FILEGROWTH = 5MB )
LOG ON
( NAME = 'Payroll_log',
   FILENAME = 'c:\program files\microsoft sql server\mssql\data\payroll.ldf',
   SIZE = 10MB,
   MAXSIZE = 40MB,
   FILEGROWTH = 5MB )
GO

Next up is the CREATE TABLE command.

Enjoy this website?

  1. Link to this page (copy/paste into your own website or blog):
  2. Add this page to your favorite social bookmarks sites:
               
  3. Add this page to your Favorites

Oh, and thank you for supporting Quackit!