Managing SQL Server - Create a Database
13 May 2009 @ 09:58AM

Updated: 25 Jan 2010 @ 01:05PM
The rest of the branches won't be of much interest to you as they're for more advanced functions of SQL such as database replication, logging, triggers, linking server and backing up. Though these are all interesting subjects, you won't need to know about them unless you're managing a SQL server in a large, multiuser environment (like a corporation).

Go ahead and right-click on the Databases branch and we'll create a new database.


Creating a Database

This may look familiar since we did it in the last tutorial. Fill out your database name in the Database name section. I called mine Clankiller. Below that is the Owner. Click the ... button to the right and you can choose one or more users to be the owner(s) of that database. Alternately you can just type in a name. Below that are the database files. These are the physical files on the hard drive that hold your database data. You can rename them if you want or alter some of their initial settings. You can also add additional database files using the Add button at the bottom. This is primarily to hold data if the primary file gets too big. I doubt you'll run into that limitation with what we're doing. The filegroups tab deals with the same subject.

The options tab has a bunch of options on how the database is configured, including things like the collation (character set). You may need to change the collation if you plan on storing non-Latin characters like Cyrillic or Chinese. Other options tend to be pretty specific. Feel free to read through this list if you want but the defaults are typically fine. When you've gotten everything set to your satisfaction, click ok to create the database. It should show up in your databases list.
Comments (0)
Right click on your database and we'll go through the options here.


Scripting Options

New database and new query should be fairly obvious. Script database as... makes SQL Server automatically generate a SQL script for you. Create to, for instance, would write out a SQL script that creates the database with your current settings. That way if you wanted to create the same database on another server you can just run that SQL script rather than manually setting it back up again or copying the datafiles.


Tasks

Under tasks we have various database tasks. Detach basically takes the entire database offline and unlocks the files. This can let you do things like copy or move the physical database files on the machine. Shrink attempts to shrink the size of the database by removing empty space. I doubt you'll need to worry about this option often. Back Up allows you to back up the database, important for a production site or if you're going to be doing things that might trash the database (like complex data/table manipulation). Restore lets you restore a backup. Generate Scripts launches the Script Wizard so you can create sql scripts for things like tables and users. I doubt you'll find yourself using this option often (or at all).

Under reports you'll find various types of reports you can run on your database. Mostly useless. The rest of the options should be fairly obvious. On the next page we'll explore the database branch.
Comments (0)