资源描述:
《门诊部数据库脚本设计脚本设计.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、门诊部数据库脚本设计-------------------------------------数据库初始化----------------------------setnocountonsetdateformatymdgoifexists(select*fromsysdatabaseswherename='hospital')dropdatabasehospitalgo-------------------------------------数据库的建立-------------------------
2、---createdatabasehospitalonprimary(name='hospital_data',filename='e:hospital.mdf',size=1,maxsize=5,filegrowth=1)logon(name='hospital_log',filename='e:hospital.ldf',size=1,maxsize=5,filegrowth=1)go--------------------------------------表的建立--------------
3、---------------------usehospitalgoifexists(select*fromsysobjectswherename='patient')droptabledbo.patientgoprint'droptablepatient'print'createpatient'go/*病人表*/createtablepatient(pat_nochar(10)notnull,----病人编号pat_namechar(10)notnull,----病人姓名ageintnotnull,-
4、---年龄sexchar(1)notnull----性别check(sexin('m','f')),allermedchar(15)null,----过敏药物primarykey(pat_no))----创建主键goinsertintodbo.patientvalues('0000000001','李红',28,'f','青霉素')insertintodbo.patientvalues('0000000002','张三',48,'m','青霉素')insertintodbo.patientvalues(
5、'0000000003','李四',21,'f','红霉素')insertintodbo.patientvalues('0000000004','田荣星',15,'f','红霉素')insertintodbo.patientvalues('0000000005','张大嘴',67,'m','红霉素')insertintodbo.patientvalues('0000000006','李霞',28,'f','红霉素')go------------------------------------------
6、----------------------------------ifexists(select*fromsysobjectswherename='doctor')droptabledbo.doctorgoprint'droptabledoctor'print'createdoctor'go/*医生表*/createtabledoctor(doc_nochar(5)notnull----医生编号check(doc_nolike'[d][0-9][0-9][0-9][0-9]'),doc_namecha
7、r(10)notnull,----医生姓名ageintnotnull,----年龄sexchar(1)notnull----性别check(sexin('m','f')),deptchar(10)notnull,----所属部门titlechar(10)notnull,----职称datehireddatetimenull,----工作日期primarykey(doc_no))----创建主键goinsertintodbo.doctorvalues('d0001','刘查理',48,'m','耳喉科',
8、'科长','1979/10/26')insertintodbo.doctorvalues('d0002','张学明',33,'m','耳喉科','主任','1986/1/20')insertintodbo.doctorvalues('d0003','赵洪亮',52,'m','妇科','科长','1970/5/16')insertintodbo.doctorvalues('d0004','尤大梅',28,'f','妇科','委员','1998