English 中文(简体)
外交关键参考资料
原标题:Foreign key referencing a 2 columns primary key in SQL Server
最佳回答

当然,有可能与一个院落(一栏以上)主要钥匙建立外国关键关系。 你没有向我们表明你为试图建立这一关系而再次做的发言——应该这样:

ALTER TABLE dbo.Content
   ADD CONSTRAINT FK_Content_Libraries
   FOREIGN KEY(LibraryID, Application)
   REFERENCES dbo.Libraries(ID, Application)

你们是否重新使用? 如果(ID, Application) is actual the main key on dbo.Libraries,则本声明应明确有效。

Luk:只是要检查——你能否在你的数据库中管理这一发言,并报告产出是什么?

SELECT
    tc.TABLE_NAME,
    tc.CONSTRAINT_NAME, 
    ccu.COLUMN_NAME
FROM 
    INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
INNER JOIN 
    INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu 
      ON ccu.TABLE_NAME = tc.TABLE_NAME AND ccu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME
WHERE
    tc.TABLE_NAME IN ( Libraries ,  Content )
问题回答

指出这些领域必须按同一顺序排列。 如果将主要钥匙称为(Application, ID)的话,那么你的外国钥匙必须参照(Application, ID)和NOT(ID, Application),因为它们被视为两个不同的钥匙。

关键是“该栏的顺序应当相同”

例:

create Table A (
    A_ID char(3) primary key,
    A_name char(10) primary key,
    A_desc desc char(50)
)

create Table B (
    B_ID char(3) primary key,
    B_A_ID char(3),
    B_A_Name char(10),
    constraint [Fk_B_01] foreign key (B_A_ID,B_A_Name) references A(A_ID,A_Name)
)

表格A栏顺序应为:>A_ID, 然后是A_Name;外国钥匙的界定也应遵循同样的顺序。

<代码>Content 的表格,凡有可能有多个重复的<代码>Application 值,可按进行测绘。 图书馆。 是否有可能将<代码>应用栏从<代码>图书馆<>/代码>初级关键索引上删除,将其改为“独特关键索引”?

我有同样的问题,我认为我有解决办法。

如果在表<编码>中你的外地<代码>>Application有外国钥匙在另一张表格中注明某一领域(代号为 I bet),那么,在表 图书馆/编码>中,您的外地<代码><>> > 申请/编码>也必须有外国钥匙上表

之后,你可以做由你组成的外国钥匙。

如果我错的话,则不使用我的贫穷的官司,也不抱歉。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...