此文章来自也算赌徒的我的关于'基于角色的访问控制'的权限管理的数据库的设计
*/
use [master]
go
-- 检查数据库 [RBAC]是否存在,如果存在则删除(只测试用,不然会丢数据.)
-- Search from the sysdatabase to see that if the [RBAC] database
exist.
-- If exists then drop it else create it.
if exists(select * from sysdatabases where name = 'RBAC')
drop database [RBAC]
go
-- 创建数据库 [RBAC]
-- Create the database named by '[RBAC]'.
create database [RBAC]
go
-- 使用数据库 [RBAC]
-- Use the database of '[RBAC]'.
use [RBAC]
go
-- 创建 "用户" 数据表 [RBAC_User]
-- Create the datatable named by '[RBAC_User]' to save users.
create table [RBAC_User]
(
--用户编号
[User_ID] int primary key not null,
--用户名称
[User_Name] varchar(20) not null,
--用户密码
[User_PassWord] varchar(20) not null,
--用户状态
[User_Lock] bit not null
)
go
-- 添加测试数据
-- Add data for test
insert into [RBAC_User]
values(1,'FightingYang','PassWord',0);
go
insert into [RBAC_User] values(2,'Supper3000','Teacher',0);
go
insert into [RBAC_User] values(3,'JianzhongLi','Teacher',1);
go
select * from [RBAC_User]
go
-- 创建 "组" 数据表 [RBAC_Group]
-- Create the datatable named by '[RBAC_Group]' to save
groups.
create table [RBAC_Group]
(
--组编号
[Group_ID] int primary key not null,
--组名称
[Group_Name] varcha