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 23.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 23.1 Using T-SQL to Create a Database

image

The database created in Listing 23.1 is relatively simple. It is named mydb and contains one data file and one log file. The data file is created on the PRIMARY filegroup; it is named mydb.mdf and is created in the C:\mssql2008\data ...

Get Microsoft® SQL Server 2008 R2 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.