17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5: Creating and Altering Tables<br />

ON<br />

118<br />

It’s worth pointing out that, when you create a new object, no one can access it except<br />

for the person who created it, the system administrator, and the database owner (which,<br />

if the object created was a database, is the same as the person that created it). This<br />

allows you to create things and make whatever adjustments you need to make before<br />

you explicitly allow access to your object.<br />

It’s also worth noting that you can use the CREATE statement only to create objects<br />

on the local server (adding in a specific server name doesn’t work).<br />

This will yield a database that looks exactly like your model database (we discussed the model database<br />

in Chapter 1). In reality, what you want is almost always different, so let’s look at a fuller syntax<br />

listing:<br />

CREATE DATABASE <br />

[ON [PRIMARY]<br />

([NAME = ,]<br />

FILENAME = <br />

[, SIZE = ]<br />

[, MAXSIZE = size in kilobytes, megabytes, gigabytes, or terabytes>]<br />

[, FILEGROWTH = ])]<br />

[LOG ON<br />

([NAME = ,]<br />

FILENAME = <br />

[, SIZE = ]<br />

[, MAXSIZE = size in kilobytes, megabytes, gigabytes, or terabytes>]<br />

[, FILEGROWTH = ])]<br />

[ COLLATE ]<br />

[ FOR ATTACH [WITH ]| FOR ATTACH_REBUILD_LOG| WITH DB_CHAINING<br />

ON|OFF | TRUSTWORTHY ON|OFF]<br />

[AS SNAPSHOT OF ]<br />

[;]<br />

Keep in mind that some of the preceding options are mutually exclusive (for example, if you’re creating<br />

for attaching, most of the options other than file locations are invalid). There’s a lot there, so let’s break<br />

down the parts.<br />

ON is used in two places: to define the location of the file where the data is stored, and to define the same<br />

information for where the log is stored. You’ll notice the PRIMARY keyword there — this means that what<br />

follows is the primary (or main) filegroup in which to physically store the data. You can also store data<br />

in what are called secondary filegroups — the use of which is outside the scope of this title. For now, stick<br />

with the default notion that you want everything in one file.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!