homework2

  • 格式:docx
  • 大小:109.58 KB
  • 文档页数:4

实验一建表
一、创建新用户
由于sys用户下不能创建触发器,因此新建用户(在sys用户下创建新用户)
代码:
create user hh --创建用户,用户名为"hh"
identified by jisuanji; --给用户设置密码为“jisuanji”
grant create session --将次权限付给hh用户(必有的)
to hh;
grant dba --将此权限给hh用户
to hh;
二、创建连接
说明:
连接名为:huihui
用户名:hh
密码:jisuanji
其余:如图中所示
三、创建表
Employees表结构
create table Employees
(
EmployeeID CHARACTER(6) PRIMARY KEY,
Name CHAR(20) NOT NULL,
Birthday Date NOT NULL,
Sex char(2) NOT NULL,
Address char(30),
PhoneNumber char(12) UNIQUE ,
DepartmentID CHAR(3) references Department(DepartmentID) )
Department表结构
Department表
create table Department (DepartmentID char(3) PRIMARY KEY, DepartmentName char(20) NOT null, Note varchar2(100)
)
Salary表结构
create table Salary
(
EmployeeID char(6),
Year NUMBER(4,0) not null,
Month number(2,0) not null,
Foundation number(8,2) not null,
CHECK(Foundation>0),
Allowance number(8,2) not null,
CHECK(Allowance>=0 AND Allowance<=10000),
Endowment number(8,2) not null,
Fund number(8,2),
constraint fk_salary foreign key(EmployeeID) references employees(employeeID), constraint PK_SALARY PRIMARY KEY(EmployeeID,Year,Month)
)。