Ⅰ工具相关PD 新建PhysicalDataModel → 菜单项(数据库) → 生成数据库 → 选择MS SQL 2005 ......Ⅱ脚本相关/*==============================================================*/ /* DBMS name: Microsoft SQL Server 2005 */ /* Created on: 2010-05-18 11:01:50 */ /*==============================================================*/ 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('tbl_Com') and o.name = 'tbl_Com_tbl_User_CommID') alter table tbl_Com drop constraint tbl_Com_tbl_User_CommID goif 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('tbl_Com') and o.name = 'tbl_Com_tbl_User_NewID') alter table tbl_Com drop constraint tbl_Com_tbl_User_NewID goif 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('tbl_FriendShip') and o.name = 'tbl_FriendShip_tbl_User_FriendUserID') alter table tbl_FriendShip drop constraint tbl_FriendShip_tbl_User_FriendUserID goif 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('tbl_FriendShip') and o.name = 'tbl_FriendShip_tbl_User_UserID') alter table tbl_FriendShip drop constraint tbl_FriendShip_tbl_User_UserID goif exists (select 1 from sysobjects where id = object_id('tbl_Com') and type = 'U') drop table tbl_Com goif exists (select 1 from sysobjects where id = object_id('tbl_FriendShip') and type = 'U') drop table tbl_FriendShip goif exists (select 1 from sysobjects where id = object_id('tbl_New') and type = 'U') drop table tbl_New goif exists (select 1 from sysobjects where id = object_id('tbl_User') and type = 'U') drop table tbl_User go/*==============================================================*/ /* Table: tbl_Com */ /*==============================================================*/ create table tbl_Com ( CommID int identity, NewID int null, UserID int null, CommContent nvarchar(MAX) null, CommDate datetime null, constraint PK_TBL_COM primary key (CommID) ) go/*==============================================================*/ /* Table: tbl_FriendShip */ /*==============================================================*/ create table tbl_FriendShip ( FriendShipID int identity, UseID int not null, FriendUseID int null, IsActive bit null, LoginTime datetime null, IsLocked bit null, constraint PK_TBL_FRIENDSHIP primary key (FriendShipID) ) go/*==============================================================*/ /* Table: tbl_New */ /*==============================================================*/ create table tbl_New ( Newid int identity, Column_2 nvarchar(30) null, Column_3 nvarchr(MAX) null, Column_4 datetime null, Column_5 datetime null, Column_6 nvarchar(20) null, constraint PK_TBL_NEW primary key (Newid) ) go/*==============================================================*/ /* Table: tbl_User */ /*==============================================================*/ create table tbl_User ( UserID int identity, UserName nvarchar(20) not null, gender bit null, Address varchar(32) null, Phone varchar(22) null, IsAdmin bit null, constraint PK_TBL_USER primary key (UserID) ) goalter table tbl_Com add constraint tbl_Com_tbl_User_CommID foreign key (UserID) references tbl_User (UserID) goalter table tbl_Com add constraint tbl_Com_tbl_User_NewID foreign key (NewID) references tbl_New (Newid) goalter table tbl_FriendShip add constraint tbl_FriendShip_tbl_User_FriendUserID foreign key (FriendUseID) references tbl_User (UserID) goalter table tbl_FriendShip add constraint tbl_FriendShip_tbl_User_UserID foreign key (UseID) references tbl_User (UserID) go
或者 你用express 创建一个数据库 再导出对应的sql 语句
create table friends(friendsid,userid)
create table news(newsid,content)
create table comm(newsid,userid,con)
Ⅰ工具相关PD 新建PhysicalDataModel
→ 菜单项(数据库) → 生成数据库 → 选择MS SQL 2005 ......Ⅱ脚本相关/*==============================================================*/
/* DBMS name: Microsoft SQL Server 2005 */
/* Created on: 2010-05-18 11:01:50 */
/*==============================================================*/
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('tbl_Com') and o.name = 'tbl_Com_tbl_User_CommID')
alter table tbl_Com
drop constraint tbl_Com_tbl_User_CommID
goif 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('tbl_Com') and o.name = 'tbl_Com_tbl_User_NewID')
alter table tbl_Com
drop constraint tbl_Com_tbl_User_NewID
goif 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('tbl_FriendShip') and o.name = 'tbl_FriendShip_tbl_User_FriendUserID')
alter table tbl_FriendShip
drop constraint tbl_FriendShip_tbl_User_FriendUserID
goif 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('tbl_FriendShip') and o.name = 'tbl_FriendShip_tbl_User_UserID')
alter table tbl_FriendShip
drop constraint tbl_FriendShip_tbl_User_UserID
goif exists (select 1
from sysobjects
where id = object_id('tbl_Com')
and type = 'U')
drop table tbl_Com
goif exists (select 1
from sysobjects
where id = object_id('tbl_FriendShip')
and type = 'U')
drop table tbl_FriendShip
goif exists (select 1
from sysobjects
where id = object_id('tbl_New')
and type = 'U')
drop table tbl_New
goif exists (select 1
from sysobjects
where id = object_id('tbl_User')
and type = 'U')
drop table tbl_User
go/*==============================================================*/
/* Table: tbl_Com */
/*==============================================================*/
create table tbl_Com (
CommID int identity,
NewID int null,
UserID int null,
CommContent nvarchar(MAX) null,
CommDate datetime null,
constraint PK_TBL_COM primary key (CommID)
)
go/*==============================================================*/
/* Table: tbl_FriendShip */
/*==============================================================*/
create table tbl_FriendShip (
FriendShipID int identity,
UseID int not null,
FriendUseID int null,
IsActive bit null,
LoginTime datetime null,
IsLocked bit null,
constraint PK_TBL_FRIENDSHIP primary key (FriendShipID)
)
go/*==============================================================*/
/* Table: tbl_New */
/*==============================================================*/
create table tbl_New (
Newid int identity,
Column_2 nvarchar(30) null,
Column_3 nvarchr(MAX) null,
Column_4 datetime null,
Column_5 datetime null,
Column_6 nvarchar(20) null,
constraint PK_TBL_NEW primary key (Newid)
)
go/*==============================================================*/
/* Table: tbl_User */
/*==============================================================*/
create table tbl_User (
UserID int identity,
UserName nvarchar(20) not null,
gender bit null,
Address varchar(32) null,
Phone varchar(22) null,
IsAdmin bit null,
constraint PK_TBL_USER primary key (UserID)
)
goalter table tbl_Com
add constraint tbl_Com_tbl_User_CommID foreign key (UserID)
references tbl_User (UserID)
goalter table tbl_Com
add constraint tbl_Com_tbl_User_NewID foreign key (NewID)
references tbl_New (Newid)
goalter table tbl_FriendShip
add constraint tbl_FriendShip_tbl_User_FriendUserID foreign key (FriendUseID)
references tbl_User (UserID)
goalter table tbl_FriendShip
add constraint tbl_FriendShip_tbl_User_UserID foreign key (UseID)
references tbl_User (UserID)
go