4.2. The CREATE Statement

In the Bible, God said, "Let there be light!" And there was light! Unfortunately, creating things isn't quite as simple for us mere mortals. We need to provide a well-defined syntax in order to create the objects in our database. To do that, we make use of the CREATE statement.

Take a look at the full structure of a CREATE statement, starting with the utmost in generality. You'll find that all the CREATE statements start out the same and then get into the specifics. The first part of the CREATE will always look like:

CREATE <object type> <object name>

This will be followed by the details that will vary by the nature of the object that you're creating.

4.2.1. CREATE DATABASE

The most basic syntax for the CREATE DATABASE statement looks like the previous example:

CREATE DATABASE <database name>

NOTE

It's worth pointing out that when you create a new object, no one can access it except for the person who created it, the system administrator and the database owner (which, if the object created was a database, is the same as the person who created it). This allows you to create things and make whatever adjustments you need to make before you explicitly allow access to your object. We will look further into how to "grant" access and security in general in Chapter 22.

It's also worth noting that you can only use the CREATE statement to create objects on the local server (adding in a specific server name doesn't work).

This will yield a database that looks ...

Get Professional SQL Server™ 2005 Programming 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.