
正文
如何使用PowerDesigner设计数据库关系模式
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
/*==============================================================*/
/* DBMS name: Microsoft SQL Server 2012 */
/* Created on: 2018/11/25 13:42:24 */
/*==============================================================*/
use "zuoye"
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('借书者') and o.name = 'FK_借书者_FK_2_借书记录')
alter table 借书者
drop constraint FK_借书者_FK_2_借书记录
go
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('图书') and o.name = 'FK_图书_FK_1_借书记录')
alter table 图书
drop constraint FK_图书_FK_1_借书记录
go
from sysobjects
where id = object_id('借书者')
and type = 'U')
drop table 借书者
go
from sysobjects
where id = object_id('借书记录')
and type = 'U')
drop table 借书记录
go
from sysobjects
where id = object_id('图书')
and type = 'U')
drop table 图书
go
/*==============================================================*/
/* Table: 借书者 */
/*==============================================================*/
create table 借书者 (
借书者编号 int not null,
图书编号 int null,
借书者姓名 ) not null,
借书数量 int null,
constraint PK_借书者 primary key (借书者编号)
)
go
/*==============================================================*/
/* Table: 借书记录 */
/*==============================================================*/
create table 借书记录 (
图书编号 int not null,
借书者编号 int null,
期望归还时间 datetime null,
借书时间 datetime null,
还书时间 datetime null,
constraint PK_借书记录 primary key (图书编号)
)
go
/*==============================================================*/
/* Table: 图书 */
/*==============================================================*/
create table 图书 (
图书编号 int not null,
书名 ) null,
作者 ) null,
出版社 ) null,
出版日期 datetime null,
库存 int null,
价格 money null,
constraint PK_图书 primary key (图书编号)
)
go
alter table 借书者
add constraint FK_借书者_FK_2_借书记录 foreign key (图书编号)
references 借书记录 (图书编号)
go
alter table 图书
add constraint FK_图书_FK_1_借书记录 foreign key (图书编号)
references 借书记录 (图书编号)
go
/*==============================================================*/
/* DBMS name: Microsoft SQL Server 2012 */
/* Created on: 2018/11/26 7:17:16 */
/*==============================================================*/
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('交易记录') and o.name = 'FK_交易记录_REFERENCE_商品')
alter table 交易记录
drop constraint FK_交易记录_REFERENCE_商品
go
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('购物者') and o.name = 'FK_购物者_REFERENCE_交易记录')
alter table 购物者
drop constraint FK_购物者_REFERENCE_交易记录
go
from sysobjects
where id = object_id('交易记录')
and type = 'U')
drop table 交易记录
go
from sysobjects
where id = object_id('商品')
and type = 'U')
drop table 商品
go
from sysobjects
where id = object_id('购物者')
and type = 'U')
drop table 购物者
go
/*==============================================================*/
/* Table: 交易记录 */
/*==============================================================*/
create table 交易记录 (
交易记录ID int not null,
交易物品ID ) not null,
交易物品数量 int not null,
交易商家ID ) not null,
constraint PK_交易记录 primary key (交易记录ID)
)
go
/*==============================================================*/
/* Table: 商品 */
/*==============================================================*/
create table 商品 (
交易物品ID ) not null,
交易物品名称 ) not null,
库存 int not null,
单价 money not null,
constraint PK_商品 primary key (交易物品ID)
)
go
/*==============================================================*/
/* Table: 购物者 */
/*==============================================================*/
create table 购物者 (
账户ID ) not null,
用户名 ) not null,
交易记录ID int not null,
交易时间 datetime not null,
constraint PK_购物者 primary key (账户ID)
)
go
alter table 交易记录
add constraint FK_交易记录_REFERENCE_商品 foreign key (交易物品ID)
references 商品 (交易物品ID)
go
alter table 购物者
add constraint FK_购物者_REFERENCE_交易记录 foreign key (交易记录ID)
references 交易记录 (交易记录ID)
go





