Introduction
A database is primarily a group of computer files that each has a name and a location. Just as there are different ways to connect to a server, in the same way, there are different ways to create a database.
To create a new database in Microsoft SQL Server Management Studio, in the Object Explorer, you can right-click the Databases node and click New Database... This would open the New Database dialog box.
Practical Learning: Creating a Login
- Make sure you had created a user account named pkatts introduced in Lesson 1.
To launch Microsoft SQL Server, click Start -> (All) Programs -> Microsoft SQL Server 2008 -> SQL Server Management Studio - On the Connect to Server dialog box, make the correct selections and provide the appropriate information, then click Connect
- In the Object Explorer, expand the server name if necessary.
Right-click Security, position the mouse on New, and click Login...
- Set the owner to ComputerName\pkatts (Windows XP or Vista) or DomainName\pkatts (Windows Server) (you can also click Search to locate the user name)
- Click OK

The Name of a Database
Probably the most important requirement of creating a database is to give it a name. The SQL is very flexible when it comes to names. In fact, it is very less restrictive than most other computer languages. Still, there are rules you must follow when naming the objects in your databases:
- A name can start with either a letter (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, or Z), a digit (0, 1, 2, 3, 4, 5, 6, 7, 8, or 9), an underscore (_) or a non-readable character. Examples are _n, act, %783, Second
- After the first character (letter, digit, underscore, or symbol), the name can have combinations of underscores, letters, digits, or symbols. Examples are _n24 or act_52_t
- A name can include spaces. Example are c0untries st@ts, govmnt (records), or gl0b# $urvey||
Because of the flexibility of SQL, it can be difficult to maintain names in a database. Based on this, there are conventions we will use for our objects. In fact, we will adopt the rules used in C/C++, C#, Pascal, Java, and Visual Basic, etc. In our databases:
- Unless stated otherwise (we will mention the exceptions, for example with variables, tables, etc), a name will start with either a letter (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, or Z) or an underscore
- After the first character, we will use any combination of letters, digits, or underscores
- A name will not start with two underscores
- If the name is a combination of words, at least the second word will start in uppercase. Examples are Countries Statistics, Global Survey, _RealSport, FullName, or DriversLicenseNumber
After creating an object whose name includes space, whenever you use that object, include its name between [ and ]. Examples are [Countries Statistics], [Global Survey], or [Date of Birth]. Even if you had created an object with a name that doesn't include space, when using that name, you can still include it in square brackets. Examples are [UnitedStations], [FullName], [DriversLicenseNumber], and [Country].
Practical Learning: Starting the Management Studio
- In the Object Explorer, right-click Databases and click New Database...

- In the Name text box, type MotorVehicleAdministration

The Owner of a Database
Whenever a new database is created, the server wants to keep track of who created that database. This is known as the database owner. By default, Microsoft SQL Server creates a special account named dbo (for database owner). When you create a database but do not specify the owner, this account is used. The dbo account is also given rights to all types of operations that can be performed on the database. This is convenient in most cases. Still, if you want, you can specify another user as the owner of the database. Of course, the account must exist, which means you should have previously created it or you can use an existing one.
To visually specify the owner of a database you are creating, you can click <default> in the Owner text box, type the name of the domain, followed by the back slash, and followed by the user name who will own the database. Alternatively, you can click the ellipsis button on the right side of the Owner text box. This would open the Select Database Owner dialog box:

In the Enter the Object Names to Select dialog box, enter the full name or the username of the user to whom you want to assign the database. After doing that, click Check Names. If the name is right, the dialog box would accept it. If the name is not right, you would receive an error. You can click the Browse button. This would open the Browse For Objects dialog box. If you see the user object you want to use, click its check box and click OK.
Practical Learning: Specifying the Database Owner
- In the Owner dialog box, click <default> and type DomainName\pkatts (replace DomainName with the name of your domain; otherwise, skip this step) (you can also click the browser button on the right side of Owner to locate and select the desired username)

The Primary Size of a Database
When originally creating a database, you may or may not know how many lists, files, or objects the project would have. Still, as a user of computer memory, the database must use a certain portion, at least in the beginning. The amount of space that a database is using is referred to as its size. If you use the New Database dialog box, after specifying the name of the database and clicking OK, the interpreter automatically specifies that the database would primarily use 2MB. This is enough for a starting database. Of course, you can either change this default later on or you can increase it when necessary.
If you want to specify a size different from the default, if you are using the New Database to create your database, in the Database Files section and under the Initial Size column, change the size as you wish.
Practical Learning: Setting the Database File Size
- In the Database Files section, click the box under the Initial Size column header, click the up arrow of the spin button and increase its value to 5

The Location of a Database
As you should be aware of already from your experience on using computers, every computer file must have a path. The path is where the file is located in one of the drives of the computer. This allows the operating system to know where the file is, so that when you or another application calls it, the operating system would not be confused.
By default, when you create a new database, Microsoft SQL Server assumes that it would be located at Drive:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA folder. If you use the New Database dialog box of the SQL Server Management Studio, if you specify the name of the database and click OK, the interpreter automatically creates a new file, and appends the .MDF extension to the file: this is the (main) primary data file of your database.
If you do not want to use the default path, you can change it. If you are using the New Database dialog box, to change the path, under the Path header, select the current string:

Replace it with an appropriate path of your choice.

Practical Learning: Checking the Location of the Data File
- Scroll to the right side and, under the Path header, notice the location of the file
- Start Windows Explorer
- In the left frame, click the C: drive
- Right-click a blank area in the right frame -> New -> Folder
- Type Microsoft SQL Server Database Development as the name of the new folder
- Return to the New Database dialog box.
Under Path, click the browse button
- Locate the Microsoft SQL Server Database Development folder you created and select it
- Do the same for the other path
- Click OK
Default Databases
When you install Microsoft SQL Server, it also installs 4 databases named master, model, msdb, and tempdb. These databases will be for internal use. This means that you should avoid directly using them, unless you know exactly what you are doing.

Practical Learning: Creating a Database Using SQL







Join the conversation! Your thoughts help the community grow.