你的代码在SQLserver无法运行,请重新写
时间: 2024-04-17 07:26:10 浏览: 73
抱歉,之前提供的代码确实不适用于 SQL Server。以下是经过修改后适用于 SQL Server 的代码:
```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)
);
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
);
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)
);
alter table Lessee add foreign key(Lessee_id) references Contract(Lessee_id);
alter table Owner add foreign key(Owner_id) references Contract(Owner_id);
alter table Owner add foreign key(Owner_id) references Let(Owner_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', '租赁中');
```
请注意,这段代码可能仍然需要根据你的数据库结构和需求进行调整。确保在运行之前已经创建了相应的数据库,并使用相应的表和列名称。
阅读全文