Creating Your Database Using SQL Server 2005
Creating Your Database Using SQL Server 2005
To start, open up the SQL Management Studio Express 2005. Fill in your log-in details to
connect to your database server.
CREATING A NEW DATABASE
To start creating a database, right click on “Databases” found in the “Object Explorer”
window found in your left then select “New Database”
A new window will appear. Type in the name of your new database and then click OK.
Once database has been added successfully, you should be able to see it once you
expand the “Databases” directory in the “Object Explorer” window. Expand the
database you created as well and you will see more folders which includes the “Tables”
CREATING A NEW TABLE
To create a new table, right click on the “Tables” folder and select new table.
Once you create a new table, a new window will appear where you will be able to put
on your fields/columns for your table. Now you can start adding your fields. So first off,
you need to add an Identity or ID field that will identify a unique data in your table.
Once you added your ID field, right click on it and select “Set Primary Key” or you just
select the newly added field and click the key icon in the toolbar above to set the field as
the primary key.
Next, we need to make sure that the ID column is auto incremented. While the ID field is
still selected, go to the column properties section found below, and look for “Identity
Specification”. Expand it and look for “Is Identity”. Make sure you select “Yes”.
Now we can add more fields in our table. Once we’re done, click the save button.
Now you will be asked to input the name of the table you’re about to save.
Now you can see your newly created table saved under the “Tables” directory of your
database. Keep creating more tables and the next step is how to create relationships
between tables.
CREATING RELATIONSHIPS
To create relations between tables, we right click on the foreign key field of another
table then select “Relationships
You’ll be taken in to the relationships properties. Click on add to add a new relationship
and it will also display the properties of that relationship.
Once you have added a new relationship, go to the “Tables and Columns Specifications”
attribute found in the relationship properties in the right side. Click on the blank value
and you’ll see a button. Click that button to start identifying our Foreign key and the
Primary key.
Now the Tables and Columns window opens. Select the appropriate Primary Key and
Foreign Key then click OK. You’ll be taken back to the Foreign Key Relationships window.
Click close and then save the table.