Link to home
Start Free TrialLog in
Avatar of CMChalcraft
CMChalcraftFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Create foreign key in sql table

Hi,

I have created this table :

CREATE TABLE [dbo].[tblGRNote](
      [PKGRNoteID] [int] IDENTITY(1,1) NOT NULL,
      [DateIn] [datetime] NULL,
      [SiteID] [nchar](8) NULL,
      [EngineerID] [nchar](6) NULL,
      [CallOutNo] [int] NULL,
      [ACCOUNT_REF] [nvarchar](8) NULL,
      [SupplierName] [nvarchar](60) NULL,
      [OrderNo] [int] NULL
)

I want to create a Foreign Key field SiteID. How do I do this?

Can I do it within Microsoft Management Studion 2008?
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ALTER TABLE tblGRNote
 ADD CONSTRAINT FK_tblGRNote_SiteID FOREIGN KEY (SiteID) REFERENCES tblSite (SiteID)

Assuming tblSite is your other table with PK of SiteID

Revised...
CMChalcraft, do you need more help on this question?
Avatar of CMChalcraft

ASKER

No thanks sorted for now.