sqlserver中 在被引用表 'A' 中没有与外键 'c2' 中的引用列列表匹配的主键或候选键
2015-05-06 17:39
148 查看
代码如下:
create table ddd
(
name varchar(10) not null,
age int not null,
constraint cc primary key(name,age)
)
create table ccc
(
gender varchar(20) not null,
id varchar(20) not null,
cname varchar(10) not null,
constraint c2 foreign key (cname) references ddd(name)
)
这样的编写会导致如上提示,
消息 1776,级别 16,状态 0,第 1 行
在被引用表 'ddd' 中没有与外键 'c2' 中的引用列列表匹配的主键或候选键。
消息 1750,级别 16,状态 0,第 1 行
无法创建约束。请参阅前面的错误消息。
修改方案:
create table ddd
(
name varchar(10) primary key not null,
age int not null,
--constraint cc primary key(name,age)
)
修改之后错误消失,原因未知,希望有类似经历的朋友给予解答,谢谢!
create table ddd
(
name varchar(10) not null,
age int not null,
constraint cc primary key(name,age)
)
create table ccc
(
gender varchar(20) not null,
id varchar(20) not null,
cname varchar(10) not null,
constraint c2 foreign key (cname) references ddd(name)
)
这样的编写会导致如上提示,
消息 1776,级别 16,状态 0,第 1 行
在被引用表 'ddd' 中没有与外键 'c2' 中的引用列列表匹配的主键或候选键。
消息 1750,级别 16,状态 0,第 1 行
无法创建约束。请参阅前面的错误消息。
修改方案:
create table ddd
(
name varchar(10) primary key not null,
age int not null,
--constraint cc primary key(name,age)
)
修改之后错误消失,原因未知,希望有类似经历的朋友给予解答,谢谢!
相关文章推荐
- 消息 1776,级别 16,状态 0,第 1 行 在被引用表 '产品类别' 中没有与外键 'FK_leibie1' 中的引用列列表匹配的主键或候选键。 消息 1750,级别 16,状态 0,第 1 行
- MySQL server version for the right syntax to use near 'OPTION SQL_SELECT_LIMIT=DEFAULT’
- mysql本地訪问linuxserver,出现SQLSTATE[HY000] [1130] Host '127.0.0.1' is not allowed to connect to this
- 040908 R Oracle & SqlServer 's ORDER -->select top & where rownum <= 3
- 无法升级数据库 'SchoolPlatForm1',因为它是只读的,或者具有只读文件。请将数据库或文件设为可写,然后重新运行恢复操作。 (Microsoft SQL Server,错误: 3415)
- PowerDesigner15 导出sql语句,但是没有主键外键
- 为什么我装完SQL Server 2000后,"SQL Server组"中没有项目,下一级显示为“无项目”
- java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect
- 无法打开用户默认数据库。登录失败/用户 'sa' 登录失败。 (Microsoft SQL Server,错误: 4064)
- sql server 外键-唯一值…
- 【mysql】【报错】Mysql外键名重复的错误:duplicate key in table '#sql-*'
- Dynamic 'Sales by Week' Procedure in SQL Server
- sqlserver中多行所有数据重复,无法更新或删除问题,通常是在没有主键的情况下的表
- vs2010不能正确加载 'VSTS for Database Professionals Sql Server Data-tier Application'包
- com.microsoft.sqlserver.jdbc.SQLServerException: 对象名 ‘xxx' 无效
- JRE1.6.0_29 can't connect to Sql Server 2008R2 with Sqljdbc4.jar
- Cause: com.microsoft.sqlserver.jdbc.SQLServerException: 关键字 'user' 附近有语法错误
- com.microsoft.sqlserver.jdbc.SQLServerException: 对象名 ‘xxx' 无效
- Login failed for user 'Tester'. Reason: Not associated with a trusted SQL Server connection.
- SQLite组合主键设置外键以及出现外键匹配出错System.Data.SQLite.SQLiteException (0x80004005) SQL logic error or missing d