Creating a SQL Server Database
Databases are at the heart of every SQL Server system. They contain the tables, database diagrams, views, stored procedures, functions, and triggers that comprise the system. This lesson covers:
- How to create a SQL Server database
- How to set database options
- How to work with the Transaction Log
- How to attach to an existing database
Creating the Database
Before you can build tables, views, stored procedures, triggers, functions, and other objects, you must create the database in which they will reside. A database is a collection of objects that relate to one another. An example would be all the tables and other objects necessary to build a sales order system. To create a SQL Server database, follow these steps:
Right-click the Databases node and select New Database. The New Database dialog box appears (see Figure 3.1).
FIGURE 3.1 The New Database dialog box enables you to create a new database.
- Enter a name for the database.
- Scroll to the right to view the path for the database.
- Click the Ellipsis button. The Locate Folder dialog box appears.
Select a path for the database (see Figure 3.2).
FIGURE 3.2 You can opt to accept the default path, or you can designate a path for the database.
- Click OK to close the Locate Folder dialog box.
Click to select the Options page and change any options as desired (see Figure 3.3).
FIGURE 3.3 The Options page of the New Database dialog box enables you to set custom options for the database.
Click OK to close the New Database dialog box and save the new database. The database now appears under the list of databases (see Figure 3.4) under the Databases node of SQL Server Management Studio. If the database does not appear, right-click the Databases node and select Refresh.
FIGURE 3.4 The new database appears under the list of databases in the Databases node.