/*创建Moonfox_db数据库*/
use master
if exists(select * from sysdatabases where name='Moonfox_db')
drop database Moonfox_db
create database Moonfox_db
on
(
name='Moonfox_db_data',
filename='D:\Visual Studio 2008 & Sql server 2005\Sql server\Moonfox_db.mdf',
size=10,
filegrowth=2MB
)
log on
(
name='Moonfox_db_log',
filename='D:\Visual Studio 2008 & Sql server 2005\Sql server\Moonfox_db.ldf',
size=5,
filegrowth=20%
)/*创建Department表*/
use Moonfox_db
if exists(select * from sysobjects where name='Department')
drop table Department
create table Department
(
DID int identity (1,1)primary key,--部门编号,主键
Dname nvarchar(20),--部门名称
Address nvarchar(50),--部门地址
Photo decimal(12,0),--电话
)/*创建Employee表*/
use Moonfox_db
if exists(select * from sysobjects where name='Employee')
drop table Employee
create table Employee
(
EID int identity (1,1)primary key,--职工编号,主键
Ename varchar(10),--职工名
Gender nchar(2) check(Gender='男' or Gender='女'),--性别,添加限制
Position nvarchar(10) check(Position='员工' or Position='组长' or Position='经理'),--职务,添加限制
Address nvarchar(50),--家庭地址
DID int,--部门编号,外键
foreign key(DID) references Department(DID)--外键约束
)
/*创建Care表*/
use Moonfox_db
if exists(select * from sysobjects where name='Care')
drop table Care
create table Care
(
CID int identity (1,1)primary key,--保健卡编号,主键
EID int,--职工号,外键
foreign key(EID) references Employee(EID),--外键约束
CheckDate datetime,--检查身体日期
PhysicalCondition nvarchar(4) check(PhysicalCondition='一般' or PhysicalCondition='差' or PhysicalCondition='好'),--健康状况
)
/*创建Care表约束*/
alter table Care
add
constraint DF_CheckDate default(getdate()) for CheckDate--缺省,默认净时间为当前计算机时间 路径自己修改,试图自己做,选择语句自己写。我该睡觉了,抱歉,你试着在sql server中运行下,我等着休息,也不知道写的有没有错误,没时间帮你写省下的了。不急着用的话我明天帮你写吧。
我用的是sql 2005 的 数据库 现在已经建好数据库了 在编写查询代码 留下邮箱 将数据库(.mdf& .log)发给你
(1):create table zhigong(zhigongid int primary key,name varchar(14),sex varchar(2),zhiwu varchar(10),address varchar(30),bumenid foreign key (bumenid) references bumentable(id))