CREATE TABLE [tblPerson](
[PersonID] [int] IDENTITY(1,1) NOT NULL,
[EmpCode] [varchar](5) NULL,
[LoginName] [varchar](50) NULL,
CONSTRAINT [PK_tblPerson] PRIMARY KEY CLUSTERED
(
[PersonID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [tblTest](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Something] [varchar](50) NULL,
[CheckedInBy] [int] NULL,
[CheckedOutBy] [int] NULL,
CONSTRAINT [PK_tblTest] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [tblTest] WITH CHECK ADD CONSTRAINT [FK_tblTest_tblPerson_CheckIn] FOREIGN KEY([CheckedInBy])
REFERENCES [tblPerson] ([PersonID])
GO
ALTER TABLE [tblTest] CHECK CONSTRAINT [FK_tblTest_tblPerson_CheckIn]
GO
ALTER TABLE [tblTest] WITH CHECK ADD CONSTRAINT [FK_tblTest_tblPerson_CheckOut] FOREIGN KEY([CheckedOutBy])
REFERENCES [tblPerson] ([PersonID])
GO
ALTER TABLE [tblTest] CHECK CONSTRAINT [FK_tblTest_tblPerson_CheckOut]
GO
|