O'Reilly logo

Microsoft® SQL Server 2012 Unleashed by Alex T. Silverstein, Chris Gallelli, Paul T. Bertucci, Ray Rankins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using T-SQL to Create Databases

Instead of using SSMS, you can use T-SQL to create a database. The T-SQL command to do this is CREATE DATABASE. The CREATE DATABASE syntax is extensive and is best illustrated with an example. Listing 19.1 shows a sample script to create a database called mydb. This script was generated using the Script option available on the New Database screen.

LISTING 19.1 Using T-SQL to Create a Database

CREATE DATABASE [mydb] ON  PRIMARY( NAME = N'mydb', FILENAME = N'C:\mssql\data\mydb.mdf' ,     SIZE = 2048KB , FILEGROWTH = 1024KB ) LOG ON( NAME = N'mydb_log', FILENAME = N'C:\mssql\log\mydb_log.ldf',     SIZE = 1024KB , FILEGROWTH = 10%)GO

The database created in Listing 19.1 is relatively ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required