请帮我看看下面代码的错误,帮我改正过来create table Contract( Contract_id char(20) primary key, Lessee_id char(20) not null unique, Owner_id char(20) not null unique, House_id char(20) not null unique, Contract_time Date not null ) create table Lessee( Lessee_id char(20) primary key, Lessee_sex char(2) not null, Lessee_address char(50) not null, Lessee_time Date not null, Lessee_state char(100) not null foreign key(Lessee_id) references Contract(Lessee_id) ) alter table Lessee add foreign key(Lessee_id) references Contract(Lessee_id); create table Owner( Owner_id char(20) primary key, Owner_sex char(2) not null, Owner_address char(50) not null, Owner_phone char(11) not null, Owner_status char(10) not null foreign key(Owner_id) references Contract(Owner_id), ) create table Let( Let_id char(20) primary key, Owner_id char(20) not null, Let_introduce char(200) not null, Let_state char(10) not null, ) alter table Owner add foreign key(Owner_id) references Let(Owner_id); create table House( House_id char(20) primary key, House_address char(50), House_area char(50) not null, House_type char(100) not null, House_money char(10) not null, House_time char(50) not null, House_state char(50) not null, foreign key(House_id) references Contract(House_id), ) insert into Contract values('2','1','李四','1 ','2023-07-07') insert into House values('2','1','70','两室一厅','3000','2023-07-07','已租赁') insert into Lessee values('张三','男','2','2023-07-07','租赁中') insert into Let values('5','李四','434636','租赁中') insert into Owner values('李四','男','434636','12124512421','租赁中')
时间: 2024-01-12 22:04:35 浏览: 162
在你的代码中有几个错误:
1. 在 `Lessee` 表中,`Lessee_state` 列缺少逗号。
2. 在 `Owner` 表中,`Owner_status` 列缺少逗号。
3. 在 `Let` 表中,`Let_state` 列缺少逗号。
4. 在 `House` 表中,`House_state` 列缺少逗号。
5. 在 `Contract` 表中,`Contract_id` 列的数据类型是 `char(20)`,但在插入数据时只提供了一个数字 `'2'`,这可能导致数据不匹配。
下面是已经修改过的代码:
```sql
create table Contract (
Contract_id char(20) primary key,
Lessee_id char(20) not null unique,
Owner_id char(20) not null unique,
House_id char(20) not null unique,
Contract_time Date not null
);
create table Lessee (
Lessee_id char(20) primary key,
Lessee_sex char(2) not null,
Lessee_address char(50) not null,
Lessee_time Date not null,
Lessee_state char(100) not null,
foreign key(Lessee_id) references Contract(Lessee_id)
);
alter table Lessee add foreign key(Lessee_id) references Contract(Lessee_id);
create table Owner (
Owner_id char(20) primary key,
Owner_sex char(2) not null,
Owner_address char(50) not null,
Owner_phone char(11) not null,
Owner_status char(10) not null,
foreign key(Owner_id) references Contract(Owner_id)
);
create table Let (
Let_id char(20) primary key,
Owner_id char(20) not null,
Let_introduce char(200) not null,
Let_state char(10) not null
);
alter table Owner add foreign key(Owner_id) references Let(Owner_id);
create table House (
House_id char(20) primary key,
House_address char(50),
House_area char(50) not null,
House_type char(100) not null,
House_money char(10) not null,
House_time char(50) not null,
House_state char(50) not null,
foreign key(House_id) references Contract(House_id)
);
insert into Contract values('2','1','李四','1','2023-07-07');
insert into House values('2','1','70','两室一厅','3000','2023-07-07','已租赁');
insert into Lessee values('1','男','2','2023-07-07','租赁中');
insert into Let values('5','李四','434636','租赁中');
insert into Owner values('李四','男','434636','12124512421','租赁中');
```
请注意,我假设 `Lessee_id` 在 `Lessee` 表中应该是主键,并且与 `Contract` 表中的 `Lessee_id` 列进行外键关联。同样,我也假设 `Owner_id` 在 `Owner` 表中是主键,并与 `Contract` 表中的 `Owner_id` 列进行外键关联。如果这些假设不正确,请根据你的需求进行更改。
阅读全文