CREATE TABLE [test_key] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[a] [int] NULL ,
[b] [int] NULL ,
[c] [int] NULL ,
CONSTRAINT [test_mkey] PRIMARY KEY NONCLUSTERED
(
[id]
) ON [PRIMARY] ,
CONSTRAINT [test_xkey] UNIQUE CLUSTERED
(
[a],
[b],
[c]
) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [test_fkey] (
[name] [int] NOT NULL ,
[age] [int] NULL ,
[id] [int] NULL ,
[a] [int] NULL ,
[b] [int] NULL ,
[c] [int] NULL ,
CONSTRAINT [test_fkey_mkey] PRIMARY KEY CLUSTERED
(
[name]
) ON [PRIMARY] ,
CONSTRAINT [test_fkey_fkey] FOREIGN KEY
(
[id]
) REFERENCES [test_key] (
[id]
)
) ON [PRIMARY]
GO
[id] [int] IDENTITY (1, 1) NOT NULL ,
[a] [int] NULL ,
[b] [int] NULL ,
[c] [int] NULL ,
CONSTRAINT [test_mkey] PRIMARY KEY NONCLUSTERED
(
[id]
) ON [PRIMARY] ,
CONSTRAINT [test_xkey] UNIQUE CLUSTERED
(
[a],
[b],
[c]
) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [test_fkey] (
[name] [int] NOT NULL ,
[age] [int] NULL ,
[id] [int] NULL ,
[a] [int] NULL ,
[b] [int] NULL ,
[c] [int] NULL ,
CONSTRAINT [test_fkey_mkey] PRIMARY KEY CLUSTERED
(
[name]
) ON [PRIMARY] ,
CONSTRAINT [test_fkey_fkey] FOREIGN KEY
(
[id]
) REFERENCES [test_key] (
[id]
)
) ON [PRIMARY]
GO
如果你想取出一条记录的话:
create ...
as
insert 另一个表 select * from inserted或deleted