实验七 PowerDesigner数据库设计 下载本文

图7-5

同样图7-5中也不是本实验要去建立的完整的物理模型,请在完成完整的概念模型后,再生成物理模型,并完善联系自身的属性。结果保存成.PDM的文件。

3. 生成数据库表

选择菜单“Database”下“Generate Database”,选定脚本文件的保存位置,如桌面,点击“确定”按钮,生成建立该数据库表的.sql脚本文件。如图7-6所示。

图7-6

查看脚本文件的内容,可在SQL Server2005中打开该脚本并运行,即生成所有的数据库表。

/*==============================================================*/ /* DBMS name: Microsoft SQL Server 2005 */ /* Created on: 2015/6/24 8:45:57 */

/*==============================================================*/

if exists (select 1

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_选课_选课_学生') alter table 选课

drop constraint FK_选课_选课_学生 go

if exists (select 1

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_选课_选课2_课程') alter table 选课

drop constraint FK_选课_选课2_课程 go

if exists (select 1

from sysobjects

where id = object_id('学生') and type = 'U') drop table 学生 go

if exists (select 1

from sysobjects

where id = object_id('课程') and type = 'U') drop table 课程 go

if exists (select 1

from sysindexes

where id = object_id('选课') and name = '选课2_FK' and indid > 0 and indid < 255) drop index 选课.选课2_FK go

if exists (select 1

from sysindexes

where id = object_id('选课') and name = '选课_FK' and indid > 0 and indid < 255) drop index 选课.选课_FK go

if exists (select 1

from sysobjects

where id = object_id('选课') and type = 'U') drop table 选课 go

/*==============================================================*/ /* Table: 学生 */ /*==============================================================*/ create table 学生 (

学号 char(8) not null, 姓名 varchar(10) not null, 性别 char(2) null, constraint PK_学生 primary key nonclustered (学号) ) go

/*==============================================================*/ /* Table: 课程 */ /*==============================================================*/ create table 课程 (

课程号 char(8) not null, 课程名 varchar(20) not null, 学分 numeric(4,2) null, constraint PK_课程 primary key nonclustered (课程号) ) go

/*==============================================================*/ /* Table: 选课 */ /*==============================================================*/ create table 选课 (

学号 char(8) not null, 课程号 char(8) not null, 成绩 numeric(4,2) null, constraint PK_选课 primary key (学号, 课程号) ) go

/*==============================================================*/ /* Index: 选课_FK */ /*==============================================================*/ create index 选课_FK on 选课 ( 学号 ASC )