?????????????????????????(database)

/*?????????*/
create database USER_INFO
/*
ON?????????????????????????????????
LOG ON??????????????????????????????塣
FILENAME????????????????洢???????????????
%Program Files%Microsoft SQLServerMSSQLData
*/
ON
(
NAME = USER_INFO_Data??
FILENAME ='d:My Documents
SQL Server 2000-DBUSER_INFO.mdf'
)
LOG ON
(
NAME = USER_INFO_log??
FILENAME ='d:My Documents
SQL Server 2000-DBUSER_INFO.ldf'
)
/*????????????*/
sp_renamedb 'USER_INFO'??'ExamSystem';
/*????????*/
drop database USER_INFO

??????????????????????????(table)

/*?????????*/
create table DEPARTMENT
(DEPT_ID         int            NOT NULL??
DEPT_NAME       varchar(20)  NOT NULL??
PARENT_DEPT_ID  int          default NULL??
primary key (DEPT_ID)
)
/*????????????*/
create table USER_INFO
(
/*?????   ????????       ?????? */
USER_NO  CHAR(6)      NOT NULL??
NAME     VARCHAR(20)  NOT NULL??
DEPT_ID  INTEGER      NOT NULL??
JOB_ID   INTEGER      NOT NULL??
GRADE    TINYINT      NOT NULL??
STATE    TINYINT      NOT NULL
primary key (USER_NO)/*????????*/
foreign key (DEPT_ID)/*??????*/
references DEPARTMENT
on delete set null
)
/*references DEPARTMENT on delete[restrict|cascade|set null]*/
1.restrict:???????DEPTMENT?е??DEPT_ID????USER_INFO???????????????DEPTMENT?е?DEPT_ID=USER_INFO.DEPT_ID?????????
2.cascade: ???????DEPTMENT?е??DEPT_ID????USER_INFO??????????????DEPTMENT?е?DEPT_ID=USER_INFO.DEPT_ID????????????USER_INFO?е???????????????
3.set null: ???????DEPTMENT?е??DEPT_ID????USER_INFO??????????????DEPTMENT?е?DEPT_ID=USER_INFO.DEPT_ID????????????USER_INFO?е?????????DEPT_ID????????null??
/*????????????*/
sp_rename 'USER_INFO'??'USER_DETAILS';
/*?????*/
drop table USER_INFO