CMChalcraft
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
CMChalcraft, do you need more help on this question?
ASKER
No thanks sorted for now.
ADD CONSTRAINT FK_tblGRNote_SiteID FOREIGN KEY (SiteID) REFERENCES tblSite (SiteID)
Assuming tblSite is your other table with PK of SiteID
Revised...