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?
CMChalcraftFinance DirectorAsked:
Who is Participating?
 
ste5anSenior DeveloperCommented:
Maybe by defining the source?

E.g.

ALTER TABLE [dbo].[tblGRNote] FOREIGN KEY ( SiteID ) REFERENCES sourcetable ( column );

Open in new window

0
 
Mike EghtebasDatabase and Application DeveloperCommented:
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...
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
CMChalcraft, do you need more help on this question?
0
 
CMChalcraftFinance DirectorAuthor Commented:
No thanks sorted for now.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.