This tip is excerpted from "SQL Server 2000 Database Development From Scratch," by Rob Hawthorne. Courtesy of InformIT.
As in most tasks within SQL Server 2000, there are many different ways to achieve the same thing. You can use a nice user interface or you can enter Transact-SQL directly against the database.
What methods are available to create a database in SQL Server 2000? Listed here are the three basic methods you can use:
- Run the Database Creation Wizard, which is contained in Enterprise Manager. This is a simple wizard that allows you to enter the parameters that you require to model your database on. Although using the wizard is an effective and simple way to create an application database, as a DBA you usually will use one of the two following methods because they are a little quicker. For this reason we will not cover the creation of a database through the wizard.
- Use the UI in Enterprise Manager to create a database. This is done by selecting the New Database option from the pop-up menu when you right-click the database folder within Enterprise Manager. This is the most common way of creating a database in SQL Server 2000, probably because of the friendly user interface you are provided. We will initially create our application database with this method.
- Enter the CREATE DATABASE Transact-SQL statement directly into Query Analyzer. This is by far the most difficult to remember (I always have trouble remembering the exact syntax), but it gives you the most flexibility and is probably the preferred way for most DBAs. The reason? The knowledge is cross-transferable. Even if you move to another database management system (heaven forbid), you will know the basic structure of the statement.
As you can see, the ability to create a database quickly and easily (by all levels of users) is well catered for in SQL Server 2000.
I am assuming that you do not have multiple hard drives. On the PC that I am using I have three separate hard drives, but not everybody will have the same configuration, so we will go with the lowest common denominator. However, if you do have the ability to specify different drives for the data and transaction logs, feel free to do so.
Well, let's get down to business!
If you do not have Enterprise Manager running, start the application now. Drill through the tree-view control and locate the Databases folder. If you right-click the Databases folder you will be presented with a pop-up menu.
The General tab is relatively limited in the actions that you can perform. Other than entering the database name the only other action is the collation name. This is used to set the type of locale configuration that the database will have. You only need to alter this if your database will talk to a computer that has a different locale setting than your server (your PC) has.
The locale refers to the way the characters on your computer are displayed and stored. The locale is set for your machine when the operating system is installed. Different countries and languages use different locale settings so that unique characters to their language can be displayed. For example, the U.S. English character set uses the Latin1_General locale.
Because we are developing our application from scratch and currently do not have a requirement to communicate with other databases, we shall leave the database default to the server's settings.
Click OK now, and SQL Server 2000 will create your first database for you! Simple, isn't it? (Note - If you don't see your new database in the Databases folder, right-click and select Refresh.)
Now select the SQLSpyNet database, right-click, and choose the Properties option.
We are going to check that the options that we set in the model database are reflected in our new database. When you are happy with the settings, click OK.
If you explore in the new database (namely the Tables, Views, and Stored Procedures folders), you will see that some database objects have already been created. These are the system objects that SQL Server 2000 uses to keep track of the objects contained in our database. For example, if you open the Tables folder you will see a list of system tables. (Note -- If you do not see the system tables, you will need to alter the registration properties of Enterprise Manager. You can do this by selecting the ServerNameInstanceName icon, right-clicking, and then selecting Edit SQL Server Registration Properties; you will see the registration dialog window.)
These system tables contain information about the schema of the database, for example the names of tables, views, and stored procedures (in the sysobjects table), the names, size, type of columns within tables (the syscolumns table), and the names and access of the users (the sysusers table). This allows SQL Server 2000 to track not only the tables, views, and stored procedures, but also the users and many other objects defined in our database.
For More Information
- What do you think about this tip? E-mail us at editor@searchDatabase.com with your feedback.
- The Best SQL Server Web Links: tips, tutorials, scripts, and more.
- Have an SQL Server tip to offer your fellow DBA's and developers? The best tips submitted will receive a cool prize--submit your tip today!
- Ask your technical SQL Server questions--or help out your peers by answering them--in our live discussion forums.
- Check out our Ask the Experts feature: Our SQL, Database Design, Oracle, SQL Server, and DB2 gurus are waiting to answer your toughest questions.