用户表 权限表 职位表 用户职位关系表 职位权限关系表--字段主外键关系 --你看看OK不 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_用户职位关系表_REFERENCE_用户表') alter table 用户职位关系表 drop constraint FK_用户职位关系表_REFERENCE_用户表 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('用户职位关系表') and o.name = 'FK_用户职位关系表_REFERENCE_职位表') alter table 用户职位关系表 drop constraint FK_用户职位关系表_REFERENCE_职位表 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('职位权限关系表') and o.name = 'FK_职位权限关系表_REFERENCE_职位表') alter table 职位权限关系表 drop constraint FK_职位权限关系表_REFERENCE_职位表 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('职位权限关系表') and o.name = 'FK_职位权限关系表_REFERENCE_权限表') alter table 职位权限关系表 drop constraint FK_职位权限关系表_REFERENCE_权限表 goif exists (select 1 from sysobjects where id = object_id('权限表') and type = 'U') drop table 权限表 goif exists (select 1 from sysobjects where id = object_id('用户职位关系表') and type = 'U') drop table 用户职位关系表 goif exists (select 1 from sysobjects where id = object_id('用户表') and type = 'U') drop table 用户表 goif exists (select 1 from sysobjects where id = object_id('职位权限关系表') and type = 'U') drop table 职位权限关系表 goif exists (select 1 from sysobjects where id = object_id('职位表') and type = 'U') drop table 职位表 go/*==============================================================*/ /* Table: 权限表 */ /*==============================================================*/ create table 权限表 ( 权限ID int not null, 角色 numeric(30) null, constraint PK_权限表 primary key (权限ID) ) go/*==============================================================*/ /* Table: 用户职位关系表 */ /*==============================================================*/ create table 用户职位关系表 ( 用户ID int null, 职位ID int null ) go/*==============================================================*/ /* Table: 用户表 */ /*==============================================================*/ create table 用户表 ( 用户ID int not null, 用户名 numeric(10) null, 密码 numeric(30) null, constraint PK_用户表 primary key (用户ID) ) go/*==============================================================*/ /* Table: 职位权限关系表 */ /*==============================================================*/ create table 职位权限关系表 ( 权限ID int null, 职位ID int null ) go/*==============================================================*/ /* Table: 职位表 */ /*==============================================================*/ create table 职位表 ( 职位ID int not null, 职位名称 nvarchar(30) null, constraint PK_职位表 primary key (职位ID) ) goalter table 用户职位关系表 add constraint FK_用户职位关系表_REFERENCE_用户表 foreign key (用户ID) references 用户表 (用户ID) goalter table 用户职位关系表 add constraint FK_用户职位关系表_REFERENCE_职位表 foreign key (职位ID) references 职位表 (职位ID) goalter table 职位权限关系表 add constraint FK_职位权限关系表_REFERENCE_职位表 foreign key (职位ID) references 职位表 (职位ID) goalter table 职位权限关系表 add constraint FK_职位权限关系表_REFERENCE_权限表 foreign key (权限ID) references 权限表 (权限ID) go
权限表
职位表
用户职位关系表
职位权限关系表--字段主外键关系
--你看看OK不
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_用户职位关系表_REFERENCE_用户表')
alter table 用户职位关系表
drop constraint FK_用户职位关系表_REFERENCE_用户表
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('用户职位关系表') and o.name = 'FK_用户职位关系表_REFERENCE_职位表')
alter table 用户职位关系表
drop constraint FK_用户职位关系表_REFERENCE_职位表
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('职位权限关系表') and o.name = 'FK_职位权限关系表_REFERENCE_职位表')
alter table 职位权限关系表
drop constraint FK_职位权限关系表_REFERENCE_职位表
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('职位权限关系表') and o.name = 'FK_职位权限关系表_REFERENCE_权限表')
alter table 职位权限关系表
drop constraint FK_职位权限关系表_REFERENCE_权限表
goif exists (select 1
from sysobjects
where id = object_id('权限表')
and type = 'U')
drop table 权限表
goif exists (select 1
from sysobjects
where id = object_id('用户职位关系表')
and type = 'U')
drop table 用户职位关系表
goif exists (select 1
from sysobjects
where id = object_id('用户表')
and type = 'U')
drop table 用户表
goif exists (select 1
from sysobjects
where id = object_id('职位权限关系表')
and type = 'U')
drop table 职位权限关系表
goif exists (select 1
from sysobjects
where id = object_id('职位表')
and type = 'U')
drop table 职位表
go/*==============================================================*/
/* Table: 权限表 */
/*==============================================================*/
create table 权限表 (
权限ID int not null,
角色 numeric(30) null,
constraint PK_权限表 primary key (权限ID)
)
go/*==============================================================*/
/* Table: 用户职位关系表 */
/*==============================================================*/
create table 用户职位关系表 (
用户ID int null,
职位ID int null
)
go/*==============================================================*/
/* Table: 用户表 */
/*==============================================================*/
create table 用户表 (
用户ID int not null,
用户名 numeric(10) null,
密码 numeric(30) null,
constraint PK_用户表 primary key (用户ID)
)
go/*==============================================================*/
/* Table: 职位权限关系表 */
/*==============================================================*/
create table 职位权限关系表 (
权限ID int null,
职位ID int null
)
go/*==============================================================*/
/* Table: 职位表 */
/*==============================================================*/
create table 职位表 (
职位ID int not null,
职位名称 nvarchar(30) null,
constraint PK_职位表 primary key (职位ID)
)
goalter table 用户职位关系表
add constraint FK_用户职位关系表_REFERENCE_用户表 foreign key (用户ID)
references 用户表 (用户ID)
goalter table 用户职位关系表
add constraint FK_用户职位关系表_REFERENCE_职位表 foreign key (职位ID)
references 职位表 (职位ID)
goalter table 职位权限关系表
add constraint FK_职位权限关系表_REFERENCE_职位表 foreign key (职位ID)
references 职位表 (职位ID)
goalter table 职位权限关系表
add constraint FK_职位权限关系表_REFERENCE_权限表 foreign key (权限ID)
references 权限表 (权限ID)
go