This is an example for defining a foreign key relationship in Microsoft SQL Server (SQLEXPRESS). There are two tables: Salesperson and Customer (see below).  After the SalepersonID column is created in the Customer, it is important to define a foreign key relationship  to ensure the referential integrity.

A. The Salesperson table.

salesperson1

B. The Customer table.

customer

C. Foreign Key Relationship

Step 1. Select the SalespersonID column of the Customer table.

Step 2. Select the menu Table Designer >> Relationships…, then the “Foreign Key Relationships” window is desplayed. Locate and click the “Tables And Columns Specification”  property.

foreignkey11

Step 3. Click the little button (foreignkey2), then the “Tables and Columns” window is displayed. Make sure that the Foreign key table is Customer. So choose the SalespersonID column as the foreign key column. Then choose Salesperson as the Primary key table; and make its ID column as the primary key column.   

foreignkey3

Step 4. Click the OK button on the “Tables and Columns” window. Then, click the Close button on the “Foreign Key Relationships” window.

Here is the link: http://asp.dotnetheaven.com/howto/doc/adoplus/DatabaseTrans.aspx.  It has examples in C#, VB, and C++.

  1. Select the My Project file in Solution Explorer  (Figure 1).
  2. Select the Application category and change the Startup form from a list (Figure 2). 

myproject.JPG

<Figure 1>

startupform.JPG

<Figure 2>

It is suggested to manage SQLEXPRESS using SQL Server Management Studio Express, which is free from Microsoft.

1. Download SQL Server Management Studio Express. Go to:

http://www.microsoft.com/downloads/details.aspx?FamilyId=C243A5AE-4BD1-4E3D-94B8-5A0F62BF7796&DisplayLang=en

 2. After install it successfully, open the studio and log on your EQLEXPRESS server. Note that the server name must include EQLEXPRESS following your machine name and Windows Authentication should be used.

connectsql.jpg

3. The Object Explorer is displayed after a successful login.

tablesql.jpg

4. To create a database, right-click the Databases folder and select the New Database menu item.

5. To create a table, right-click the Tables folder and select the New Table menu item. 

  1. Set the column data type to int, bigint or smallint.
  2. Locate the (Is Identity) field in the Column Properties window.
  3. Set the (Is Identity)  value to be true.

autonumber.jpg