`
pangwu86
  • 浏览: 115836 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Nutz+ExtJS示例教程——数据库设计

    博客分类:
  • nutz
阅读更多

 

因为这里只是个简单的Demo,所以设计上就简单点了。

 

大概的想法就是一个通讯录跟博客,当然是非常简单的那种。

 

一共有4张表。

 

用户表,联系人表,联系人类别表,博客表。

 

 

 

简单介绍下

 

每个用户都有个人通讯录,通讯录下添加联系人,联系人可以分类。

用户还可以写Blog,其他用户可以查看你公开的Blog

 

当然这个基础上,可以加入例如好友,收藏,评论等等功能,这个根据后面的情况,如果能反映某个技术难点的话,再添加上去。

 

 

简述下这个过程:

 

新建一个数据库

 

 

 

打开PowerDesigner,新建一个PDMPhysical Data Model,其实就是表设计

 

 

 

使用Palette上控件,完成数据库设计

 

 

 

设计结果

 

 

直接生成SQL

 

 

在数据库中执行SQL

 

 

如果你也是使用Navicat执行SQL文的话,这里要注意一点,生成的SQL文开头部分,有删除索引的语句,在第一次执行时,要先删掉这段,否则会报错,无法建立表。

 

 

 

执行成功后,可以看到表建立好了

 

 

 

生成的SQL文如下:

/*==============================================================*/
/* DBMS name:      MySQL 5.0                                    */
/* Created on:     2011-2-20 23:25:35                           */
/*==============================================================*/


drop index titleIndex on t_blog;

drop index modifyTimeIndex on t_blog;

drop table if exists t_blog;

drop index emailIndex on t_contact;

drop index cellphoneIndex on t_contact;

drop index userNameIndex on t_contact;

drop table if exists t_contact;

drop index userTypeIndex on t_contact_type;

drop table if exists t_contact_type;

drop table if exists t_user;

/*==============================================================*/
/* Table: t_blog                                                */
/*==============================================================*/
create table t_blog
(
   id                   int not null auto_increment comment '唯一主键',
   userId               int comment '用户id',
   title                varchar(100) comment '标题',
   content              varchar(1000) comment '内容',
   isPublic             varchar(4) comment '是否公开(1.私有 2.公开)',
   createTime           timestamp comment '创建时间',
   modifyTime           timestamp comment '修改时间',
   primary key (id)
);

alter table t_blog comment '博客表';

/*==============================================================*/
/* Index: modifyTimeIndex                                       */
/*==============================================================*/
create index modifyTimeIndex on t_blog
(
   modifyTime
);

/*==============================================================*/
/* Index: titleIndex                                            */
/*==============================================================*/
create index titleIndex on t_blog
(
   title
);

/*==============================================================*/
/* Table: t_contact                                             */
/*==============================================================*/
create table t_contact
(
   id                   int not null auto_increment comment '唯一主键',
   userId               int comment '用户id',
   contactTypeId        int comment '联系人类别Id',
   contactName          varchar(50) comment '联系人名',
   sex                  varchar(10) comment '性别',
   birthday             date comment '生日',
   telephone            varchar(20) comment '电话',
   mobilephone          varchar(20) comment '手机',
   qq                   varchar(20) comment 'QQ号',
   msn                  varchar(20) comment 'MSN号',
   email                varchar(50) comment '电子邮件',
   address              varchar(50) comment '家庭住址',
   remark               varchar(100) comment '备注',
   primary key (id)
);

alter table t_contact comment '联系人表';

/*==============================================================*/
/* Index: userNameIndex                                         */
/*==============================================================*/
create index userNameIndex on t_contact
(
   contactName
);

/*==============================================================*/
/* Index: cellphoneIndex                                        */
/*==============================================================*/
create index cellphoneIndex on t_contact
(
   mobilephone
);

/*==============================================================*/
/* Index: emailIndex                                            */
/*==============================================================*/
create index emailIndex on t_contact
(
   email
);

/*==============================================================*/
/* Table: t_contact_type                                        */
/*==============================================================*/
create table t_contact_type
(
   id                   int not null auto_increment comment '唯一主键',
   userId               int comment '用户id',
   typeName             varchar(20) comment '类别名称',
   primary key (id)
);

alter table t_contact_type comment '联系人类别表';

/*==============================================================*/
/* Index: userTypeIndex                                         */
/*==============================================================*/
create unique index userTypeIndex on t_contact_type
(
   typeName
);

/*==============================================================*/
/* Table: t_user                                                */
/*==============================================================*/
create table t_user
(
   id                   int not null auto_increment comment '唯一主键',
   userName             varchar(30) comment '用户名',
   password             varchar(20) comment '密码',
   userType             varchar(10) comment '用户类型(1.管理员 2.普通用户)',
   primary key (id)
);

alter table t_user comment '用户表';

alter table t_blog add constraint FK_Reference_4 foreign key (userId)
      references t_user (id) on delete restrict on update restrict;

alter table t_contact add constraint FK_Reference_1 foreign key (contactTypeId)
      references t_contact_type (id) on delete restrict on update restrict;

alter table t_contact add constraint FK_Reference_2 foreign key (userId)
      references t_user (id) on delete restrict on update restrict;

alter table t_contact_type add constraint FK_Reference_3 foreign key (userId)
      references t_user (id) on delete restrict on update restrict;
 

 

以上操作,其中关于Powerdesigner的使用问题,可以参照另一篇Bloghttp://pangwu86.iteye.com/blog/910647),这里不再重复。

 

下一集,将开始讲述后台代码的Dao这层的编写。

 

1
0
分享到:
评论
1 楼 tywo45 2011-08-03  
博主加油!

相关推荐

Global site tag (gtag.js) - Google Analytics