外键“ id_client”引用表“ nrcomanda”中的无效列“ id_client”

时间:2019-02-06 20:39:16

标签: sql sql-server

  

外键“ id_client”引用无效的列“ id_client”   引用表'nrcomanda'。

use Logistica

create table client
(
id_client int primary key identity(1,1),
nume varchar(20) not null,
prenume varchar(20) not null,
id_nrc int foreign key references nrcomanda(id_nrc)
)

create table categorie
(
id_categorie int primary key identity(1,1),
categorie varchar(50),
)

create table pachet
(
id_pachet int primary key identity(1,1),
tip_pachet varchar(50)
)

create table transport
(
id_transport int primary key identity(1,1),
tip_transport varchar(20)
)

create table nrcomanda
(
id_nrc int primary key identity(1,1),
nrcomanda varchar not null,
greutate decimal(7,2),
asigurare varchar(50), 
foreign key(id_client) references client(id_client),
foreign key(id_categorie) references categorie(id_categorie),
foreign key(id_pachet) references pachet(id_pachet),
foreign key(id_transport) references transport(id_transport),
foreign key(id_adresa) references adresa(id_adresa)
)
create table raion
(
id_raion int primary key identity(1,1),
nume varchar(50) 
)

create table localitate
(
id_loc int primary key identity(1,1),
id_raion int,
nume varchar(50)
foreign key(id_raion) references raion(id_raion)
)

create table adresa
(
id_adresa int primary key identity(1,1),
id_raion int foreign key references raion(id_raion),
id_loc int foreign key references localitate(id_loc),
id_nrc int foreign key references nrcomanda(id_nrc),
id_tara int foreign key references tara(id_tara),
strada varchar(30),
nr varchar(6),
ap varchar(6),
bloc varchar(6),
activ bit default 1
)

create table tara
(
id_tara int primary key identity(1,1),
nume varchar(20)
)

1 个答案:

答案 0 :(得分:1)

我认为您在创建表中错过了一些列定义:

+-------+-----------+-------+-------+-----------+----------+-----------+
| unit  | variable1 | Value | unit2 | variable2 |  value2  | Hierarchy |
+-------+-----------+-------+-------+-----------+----------+-----------+
| 96702 | lvl0      | 80000 | 96702 | lvl0_nm   | thing 6  |           |
| 96702 | lvl1      | 80393 | 96702 | lvl1_nm   | thing 7  |           |
| 96702 | lvl2      | 85176 | 96702 | lvl2_nm   | thing 8  |           |
| 96702 | lvl3      | 82282 | 96702 | lvl3_nm   | thing 9  | User      |
| 96702 | lvl4      | 87927 | 96702 | lvl4_nm   | thing 10 |           |
| 96702 | lvl5      | 88172 | 96702 | lvl5_nm   | thing 11 |           |
| 96702 | lvl6      | 81025 | 96702 | lvl6_nm   | thing 12 |           |
| 96702 | lvl7      | 96702 | 96702 | lvl7_nm   |          |           |
| 96702 | lvl8      |       | 96702 | lvl8_nm   |          |           |
| 96702 | lvl9      |       | 96702 | lvl9_nm   |          |           |
| 96702 | lvl10     |       | 96702 | lvl10_nm  |          |           |
| 96702 | lvl11     |       | 96702 | lvl11_nm  |          |           |
| 96702 | lvl12     |       | 96702 | lvl12_nm  |          |           |
| 96702 | lvl13     |       | 96702 | lvl13_nm  |          |           |
| 96702 | lvl14     |       | 96702 | lvl14_nm  |          |           |
| 96702 | lvl15     |       | 96702 | lvl15_nm  |          |           |
| 96702 | lvl16     |       | 96702 | lvl16_nm  |          |           |
| 96702 | lvl17     |       | 96702 | lvl17_nm  |          |           |
| 96702 | lvl18     |       | 96702 | lvl18_nm  |          |           |
+-------+-----------+-------+-------+-----------+----------+-----------+