简体   繁体   中英

Give value instead of column on foreign key in sql server 2008

I have two tables TABLE_ACCOUNT and TABLE_ACTYPE .

The TABLE_ACCOUNT has columns

 (CODE, NAME, TRADE, CATGORY, ACTYPE)

and the TABLE_ACTYPE has columns

(CODE, NAME, ITYPE)

The data in the TABLE_ACTYPE is:

CODE     NAME     ITYPE
-----------------------
1        TRADE1    1
1        CAT1      2
1        ACT1      3

Primary key for this table is CODE, TYPE

The data in the TABLE_ACCOUNT is :

CODE, NAME, TRADE, CATEGORY, ACTYPE
-----------------------------------
1     Name1  1       1          1

I want to create the 3 foreign keys for to table_account

ALTER TABLE TABLE_ACCOUNT WITH CHECK 
ADD CONSTRAINT FK_TABLE_ACCOUNT_TABLE_ACTYPE_TRADE 
FOREIGN KEY ([TRADE,1]) REFERENCES [TABLE_ACTYPE] (CODE, ITYPE)

ALTER TABLE TABLE_ACCOUNT WITH CHECK 
ADD CONSTRAINT FK_TABLE_ACCOUNT_TABLE_ACTYPE_CAT 
FOREIGN KEY ([TRADE,2]) REFERENCES [TABLE_ACTYPE] (CODE, ITYPE)

ALTER TABLE TABLE_ACCOUNT WITH CHECK 
ADD CONSTRAINT FK_TABLE_ACCOUNT_TABLE_ACTYPE_ACTYPE 
FOREIGN KEY ([TRADE,3]) REFERENCES [TABLE_ACTYPE] (CODE, ITYPE)

Is this possible??

没有。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM