final design of OA project part 1
if exists (select * from sysdatabases where name='myoa')
drop database myoa
go
create database myoa
use myoa
go
if exists (select * from sysobjects where name='T_subjects' )/*公告欄目*/
drop table T_subjects
go
create table T_subjects
(
subjectid int identity primary key,
subjectname varchar(50)not null
)
insert into T_subjects values('企業文化學習')
insert into T_subjects values('技術知識')
insert into T_subjects values('公司內部章程')
if exists (select * from sysobjects where name='T_announcement' )/*公告*/
drop table T_announcement
go
create table T_announcement
(
announcementid int identity primary key,
announcementname varchar(50) not null,
announcementSubject int not null,
adduser int not null,
adddepartment int not null,
addtime varchar(50)not null,
deadline varchar(50)not null
)
select * from T_announcement
insert into T_announcement values('企業新知識文化學習',1,2,1,'2008-04-01',4,'有關企業新知識文化的學習,已經向個部門主管下發了有關企業新知識文化的學習資料,請各部門積極學習有關資料,提升員工在企業內部對企業文化的學習')
alter table T_announcement add constraint fk_adduser foreign key (adduser) references T_user(userid)
alter table T_announcement add constraint fk_adddepartment foreign key (adddepartment) references T_department(departmentid)
alter table T_announcement add constraint fk_announcementSubject foreign key (announcementSubject) references T_subjects(subjectid)
alter table T_announcement add column
select departmentname from T_department,T_user where T_user.userdepartment=T_department.departmentid and T_user.username='admin'
if exists (select * from sysobjects where name='T_department')/*部門表*/
drop table T_department
go
create table T_department
(
departmentid int identity primary key,
departmentname varchar(50)not null,
)
alter table T_department add departmentgrade int
alter table T_department add constraint fk_departmentgrade foreign key(departmentgrade) references T_departmentgrade(departmentgradeid)
insert into T_department values('生產部')
if exists (select * from sysobjects where name='T_user')/*使用者表*/
drop table T_user
go
create table T_user
(
userid int identity primary key,
username varchar(20)not null,
userage varchar(4)not null,
useraddress varchar(100)not null,
userdepartment int not null,
userposition int not null
)
select * from T_user
update T_user set usersex='女',useridenti='610101198112150512' where userid=1
alter table T_user add usersex varchar(2)
alter table T_user add useridenti varchar(18)
alter table T_user add constraint ck_useridenti check(len(useridenti)=15 or len(useridenti)=18)
select * from T_user
alter table T_user add constraint ck_username check (len(username)<20)
alter table T_user add constraint ck_userage check(userage>1 and userage<100)
alter table T_user add constraint ck_userage1 check(userage like '[0-9]%[0-9]')
insert into T_user values('sss','23','xa',1,1,'aaa')
insert into T_user values('admin0','25','xian',1,1,'aaa')
alter table T_user add constraint fk_userdepartment foreign key (userdepartment) references T_department(departmentid)
alter table T_user add constraint fk_userposition foreign key (userposition) references T_position(positionid)
if exists (select * from sysobjects where name='T_position')/*職位表*/
drop table T_position
go
create table T_position
(
positionid int identity primary key,
positionname varchar(30)not null
)
insert into T_position values('普通員工')
create view View_announcement as
select a.announcementid,a.announcementname,a.addtime,a.deadline,b.subjectname,c.username,d.departmentname
from T_announcement as a,T_subjects as b,T_user as c,T_department as d where a.announcementSubject=b.subjectid and a.adduser=c.userid and a.adddepartment=d.departmentid
if exists (select * from sysobjects where name='T_airplane')/*飛機時刻表*/
begin drop table T_airplane
end
go
create table T_airplane
(
airplaneid int identity primary key,
airplanename varchar(30) not null,
startpoint varchar(30) not null,
endpoint varchar(30) not null,
startdate datetime not null,
enddate datetime not null,
aircompany varchar(30) not null,
airplanetype varchar(30) not null,
price money not null
)
if exists (select * from sysobjects where name='T_train')/*列車時刻表*/
begin drop table T_train
end
go
create table T_train
(
trainid int identity primary key,
trainname varchar(30)not null,
startpoint varchar(30)not null,
endpoint varchar(30)not null,
startdate datetime not null,
enddate datetime not null,
traintype varchar(30) not null,
price money
)
if exists (select * from sysobjects where name='T_province')/*省份*/
begin drop table T_province
end
go
create table T_province
(
provinceid int identity primary key,
provincename varchar(30)not null
)
if exists (select * from sysobjects where name='T_post')/*郵政編碼*/
begin drop table T_post
end
go
create table T_post
(
postid int identity primary key,
provinceid int not null,
city varchar(20) not null,
postcode varchar(7) not null,
areano varchar(4)not null
)
alter table T_post add constraint fk_province
foreign key (provinceid) references T_province(provinceid)
if exists (select * from sysobjects where name='T_phone')/*電話*/
begin drop table T_phone
end
go
create table T_phone
(
phoneid int identity primary key,
type varchar(30)not null,
departmentid int not null,
phoneno varchar(20)not null
)
alter table T_phone add constraint fk_phone foreign key (departmentid)
references T_department(departmentid)
if exists (select * from sysobjects where name='T_magzinesort')/*報刊分類*/
begin drop table T_magzinesort
end
go
create table T_magzinesort
(
magzinesortid int identity primary key,
magzinesortname varchar(50) not null
)
alter table T_magzinesort add managemagzineuserid int
alter table T_magzinesort add constraint fk_magzu foreign key (managemagzineuserid) references T_user(userid)
select * from T_magzinesort
if exists (select * from sysobjects where name='T_magzine')/*報刊*/
begin drop table T_magzine
end
go
create table T_magzine
(
magzineid int identity primary key,
magzinename varchar(30)not null,
magzinsortid int not null,
adduserid int not null,
adddepartmentid int not null,
adddate datetime not null
)
select * from T_magzine
alter table T_magzine add constraint fk_magzinesortid foreign key (magzinsortid) references T_magzinesort(magzinesortid)
alter table T_magzine add constraint fk_adduserid foreign key (adduserid) references T_user(userid)
alter table T_magzine add constraint fk_adddepartmentid foreign key(adddepartmentid) references T_department(departmentid)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10395457/viewspace-1003230/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- OA projectProject
- 基於Vue JS, Webpack 以及Material Design的漸進式web應用 [Part 1]VueJSWebMaterial Design
- Webshell-Part1&Part2Webshell
- React with webpack - part 1ReactWeb
- ZeroMQ分享-part1MQ
- postgresql學習-Part 1SQL
- RMAN 常用命令 1 [final]
- Study Plan For Algorithms - Part1Go
- Final Cut Pro中文新手教程 (1) 基礎認識Final Cut Pro
- SQLMap的前世今生(Part1)SQL
- Part1 17個題目
- 使用Project 2000管理專案(1)(轉)Project
- JBoss Wildfly (1) —— 7.2.0.Final編譯編譯
- [SwiftUI 100天] WorldScramble · part1SwiftUI
- [SwiftUI 100 天] iExpense - part1SwiftUI
- 前端測試:Part1 (介紹)前端
- [譯] part18: golang 介面 1Golang
- Flutter 入門指北(Part 1)之 DartFlutterDart
- 【譯】NodeJS事件迴圈 Part 1NodeJS事件
- Canvas基礎-粒子動畫Part1Canvas動畫
- 個人收藏oracle模擬題part 1Oracle
- CSS2基礎(part-1)CSS
- Writing your first Django app, part 1DjangoAPP
- [MetalKit]31-Shadows-in-Metal-part-1陰影1
- [MetalKit]2-Using-MetalKit-part-1使用MetalKit1
- Oracle AWR 介紹及報告分析(1) finalOracle
- IDAPython 讓你的生活更滋潤 part1 and part2Python
- [SwiftUI 100天] Bucket List - part1SwiftUI
- SQLMAP原始碼分析Part1:流程篇SQL原始碼
- [SwiftUI 100 天] Cupcake Corner - part1SwiftUIPCA
- CCNA-Part1:網路基礎概念
- [part 1] 第一個 Django 應用程式Django
- 《軟體工程思想》讀書摘抄 Part 1軟體工程
- 【tidyverse】part1:資料匯入
- Dagger2學習之路(Part 1)
- MySQL效能分析和優化-part1MySql優化
- sql for modeling part1SQL
- C++課作業 魔獸世界Part 1C++