政治体制改革内容:sql提示错误1776 不知如何是好,非常着急,请高手指教

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/09 12:46:06
本人正在做一个电费管理的数据库,在建表时就出现了问题,进行不下去了,请高手指教

create database 电费管理系统
on (
name='电费管理数据库',
filename='D:\电费管理系统设计与实现\电费管理sql\电费管理数据库.MDF',
size=10MB,
maxsize=50MB,
filegrowth=5MB
)

log on
(
name='电费管理日志',
filename='D:\电费管理系统设计与实现\电费管理sql\电费管理日志.LDF',
size=1MB,
maxsize=5MB,
filegrowth=10%
)

create table 电表基本信息

(ID char(8) not null,
电表编号 char(8) not null,
户号 char(8) not null,
户名 char(8) not null,
小区编号 char(4) not null,
所属小区 char(20)not null,
抄表员流水号 char(4) not null,
抄表员姓名 char(4) not null,
操作员流水号 char(4) not null,
操作员姓名 char(4) not null,
primary key (电表编号 ,户号,小区编号 ,抄表员流水号 , 操作员流水号)
)

create table 抄表
(

抄表员流水号 char(8) not null,
抄表日期 datetime not null,
抄表员姓名 char(8) not null,
所属小区 char(8) not null,
小区编号 char(4),
户号 char(4) not null,
户名 char(20) not null,
操作员流水号 char(4),
电表编号 int not null,
电表原码 int not null,
电表止码 int not null,
用电量 int not null,
primary key (抄表员流水号,电表原码 , 电表止码 ,用电量,抄表日期 ),

foreign key (户号) references dbo.电表基本信息(户号),
foreign key (小区编号) references dbo.电表基本信息(小区编号),
foreign key (抄表员流水号) references dbo.电表基本信息(抄表员流水号),
foreign key (操作员流水号) references dbo.电表基本信息(操作员流水号),
foreign key (电表编号) references dbo.电表基本信息(电表编号));

前面都没有错,在运行创建“抄表”时,出现问题提示:

服务器: 消息 1776,级别 16,状态 1,行 1
在被引用表 'dbo.电表基本信息' 中没有与外键 'FK__抄表__户号__47DBAE45' 的引用列的列表匹配的主键或候选键。
服务器: 消息 1750,级别 16,状态 1,行 1
未能创建约束。请参阅前面的错误信息。

不知道为什么,请高手详细告之,很着急,谢谢谢谢!!!!

由于都是 NOT NULL 所以,创建 约束有问题