Adding Additional Objects To A Database Project



By:

Overview

We've created a table but it needs a primary key. Also, we could use some stored procedures to access the data we add to the table.

Explanation

Adding additional objects is just as easy as what we went through to add our table. Let's add a primary key to the table we just created.

In the Schema View, right click Keys under the table we just created. The option to Add a primary key will appear:

In the Schema View, right click Keys

Clicking on Primary Key... again presents the Add New Item screen. The Name field will default to some value. We change this value to PK_FootBallClub and click Add:

Clicking on Primary Key... again presents the Add New Item screen

A script window will again appear with a template script. We change the template code as follows to match the primary key we want to maintain.

A script window will again appear with a template script.

Saving the changes, the Schema View will show the primary key under Keys for the table.

Creating stored procedures are also a snap. Again under Schema View, we right click on Stored Procedures under Programmability and choose Stored Procedure...

right click on Stored Procedures under Programmability and choose Stored Procedure...

Again, the Add New Item appears and we create our first stored procedure

the Add New Item appears and we create our first stored procedure

A template screen with a default template code for your procedure will appear. We change the template code as follows to define our procedure:

change the template code as follows

Repeating the steps we went through for the 1st procedure, we create a 2nd procedure which is a child procedure to the first procedure we created

Repeating the steps we went through for the 1st procedure

Last Update: 9/10/2011






Comments For This Article





download


get free sql tips
agree to terms


Learn more about SQL Server tools