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.
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 ...
Get Microsoft® SQL Server 2012 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.