4.windows和Linux下创建oracle用户名表空间,表,插入数据,用户管理表等操作

进入超级管理员,执行以下命令

Window下创建数据库,表空间,用户,插入数据等操作

-- 01 创建表空间

-- 注意表空间的路径 根据实际安装环境进行调整

CREATE TABLESPACE ts_myscott

    LOGGING

    DATAFILE 'F:/app/to-to/oradata/orcl/ts_myscott.dbf' SIZE 10M

    EXTENT MANAGEMENT LOCAL;

   

CREATE TABLESPACE ts_myscott2

    LOGGING

    DATAFILE 'F:/app/to-to/oradata/orcl/ts_myscott2.dbf' SIZE 20M

    EXTENT MANAGEMENT LOCAL;

   

ALTER DATABASE DATAFILE 'F:/app/to-to/oradata/orcl//ts_myscott.dbf' AUTOEXTEND ON NEXT  10M MAXSIZE UNLIMITED;

ALTER DATABASE DATAFILE 'F:/app/to-to/oradata/orcl/ts_myscott2.dbf' AUTOEXTEND ON NEXT  20M MAXSIZE UNLIMITED;

 

commit;

 

-- 02 创建方案 (创建用户)

CREATE USER MYSCOTT  PROFILE DEFAULT

    IDENTIFIED BY MYSCOTT DEFAULT TABLESPACE USERS

    ACCOUNT UNLOCK;

 

-- 资源和登录权限

GRANT RESOURCE TO MYSCOTT;

GRANT create session TO MYSCOTT;

 

 

-- 03 创建表

-- 创建部门表 并赋值

CREATE TABLE MYSCOTT.DEPT(

         DEPTNO     NUMBER(2) PRIMARY KEY,

        DNAME       VARCHAR2(14) NOT NULL,

        LOC          VARCHAR2(13)

)TABLESPACE ts_myscott;

 

INSERT INTO MYSCOTT.dept VALUES(10, 'ACCOUNTING', 'NEW YORK');

INSERT INTO MYSCOTT.dept VALUES(20, 'RESEARCH', 'DALLAS');

INSERT INTO MYSCOTT.dept VALUES(30, 'SALES', 'CHICAGO');

INSERT INTO MYSCOTT.dept VALUES(40, 'OPERATIONS', 'BOSTON');

 

commit;

 

-- 创建员工表 并赋值

CREATE TABLE MYSCOTT.EMP(

         EMPNO           NUMBER(4) constraint emp_empno_pk PRIMARY KEY,

         ENAME                   VARCHAR2(10) constraint emp_ename_notnull NOT NULL,

         JOB              VARCHAR2(9),

         MGR                     NUMBER(4),

         HIREDATE         DATE,

         SAL               NUMBER(7,2) constraint emp_sal_check check (SAL>0),

         COMM                  NUMBER(7,2),

         DEPTNO           NUMBER(2) constraint emp_deptno_fk references MYSCOTT.dept(deptno)

)TABLESPACE ts_myscott;

 

--创建索引 在新的表空间上

CREATE  INDEX MYSCOTT.IX_CAtbAuditOperInfo_OT ON MYSCOTT.EMP(ENAME) TABLESPACE ts_myscott2;

 

 

INSERT INTO MYSCOTT.EMP VALUES(7369, 'SMITH', 'CLERK', 7902, '17-12-80', 800, NULL, 20);

INSERT INTO MYSCOTT.EMP VALUES(7499, 'ALLEN', 'SALESMAN', 7698, '20-2 -81', 1600, 300, 30);

INSERT INTO MYSCOTT.EMP VALUES(7521, 'WARD', 'SALESMAN', 7698, '22-2 -81', 1250, 500, 30);

 

INSERT INTO MYSCOTT.EMP VALUES(7566, 'JONES', 'MANAGER', 7839, '02-4 -81', 2975, NULL, 20);

INSERT INTO MYSCOTT.EMP VALUES(7654, 'MARTIN', 'SALESMAN', 7698, '28-9 -81', 1250, 1400, 30);

INSERT INTO MYSCOTT.EMP VALUES(7698, 'BLAKE', 'MANAGER', 7839, '01-5 -81', 2850, NULL, 30);

 

INSERT INTO MYSCOTT.EMP VALUES(7782, 'CLARK', 'MANAGER', 7839, '09-6 -81', 2450, NULL, 10);

INSERT INTO MYSCOTT.EMP VALUES(7788, 'SCOTT', 'ANALYST', 7566, '19-4 -87', 3000, NULL, 20);

INSERT INTO MYSCOTT.EMP VALUES(7839, 'KING', 'PRESIDENT', NULL, '17-11-81', 5000, NULL, 10);

 

INSERT INTO MYSCOTT.EMP VALUES(7844, 'TURNER', 'SALESMAN', 7698, '08-9 -81', 1500, 0, 30);

INSERT INTO MYSCOTT.EMP VALUES(7876, 'ADAMS', 'CLERK', 7788, '23-5 -87', 1100, NULL, 20);

INSERT INTO MYSCOTT.EMP VALUES(7900, 'JAMES', 'CLERK', 7698, '03-12-81', 950, NULL, 30);

 

INSERT INTO MYSCOTT.EMP VALUES(7902, 'FORD', 'ANALYST', 7566, '03-12-81', 3000, NULL, 20);

INSERT INTO MYSCOTT.EMP VALUES(7934, 'MILLER', 'CLERK', 7782, '23-1 -82', 1300, NULL, 10);

 

commit;

 

-- 创建工资级别表 并赋值

CREATE TABLE MYSCOTT.SALGRADE(

        GRADE             NUMBER,

        LOSAL           NUMBER,

        HISAL           NUMBER

)TABLESPACE ts_myscott;

 

INSERT INTO MYSCOTT.SALGRADE VALUES(1, 700, 1200);

INSERT INTO MYSCOTT.SALGRADE VALUES(2, 1201, 1400);

INSERT INTO MYSCOTT.SALGRADE VALUES(3, 1401, 2000);

INSERT INTO MYSCOTT.SALGRADE VALUES(4, 2001, 3000);

INSERT INTO MYSCOTT.SALGRADE VALUES(5, 3001, 9999);

commit;

 

--创建奖金表

CREATE TABLE MYSCOTT.BONUS(

         ENAME      VARCHAR2(10),

        JOB       VARCHAR2(9),

        SAL             NUMBER,

        COMM      NUMBER

)TABLESPACE ts_myscott;

 

------停止-----

-- 04创建新用户方案   通过MYSCOTTUSER1来访问数据库, 权限配置演示 

CREATE USER "MYSCOTTUSER1"  PROFILE "DEFAULT" IDENTIFIED BY "123456" DEFAULT TABLESPACE "USERS" ACCOUNT UNLOCK;

GRANT "CONNECT" TO "MYSCOTTUSER1";

GRANT SELECT ANY TABLE TO "MYSCOTTUSER1";

 

GRANT DELETE ON MYSCOTT.DEPT TO "MYSCOTTUSER1";

GRANT INSERT ON MYSCOTT.DEPT TO "MYSCOTTUSER1";

GRANT UPDATE ON MYSCOTT.DEPT TO "MYSCOTTUSER1";

 

GRANT DELETE ON MYSCOTT.EMP TO "MYSCOTTUSER1";

GRANT INSERT ON MYSCOTT.EMP TO "MYSCOTTUSER1";

GRANT UPDATE ON MYSCOTT.EMP TO "MYSCOTTUSER1";

 

commit;

Linux下创建数据库,表空间,用户,插入数据等操作

-- 01 创建表空间

-- 注意表空间的路径 根据实际安装环境进行调整

CREATE TABLESPACE ts_myscott

    LOGGING

    DATAFILE '/home/oracle_11/app/oradata/orcl/ts_myscott.dbf' SIZE 10M

    EXTENT MANAGEMENT LOCAL;

   

CREATE TABLESPACE ts_myscott2

    LOGGING

    DATAFILE '/home/oracle_11/app/oradata/orcl/ts_myscott2.dbf' SIZE 20M

    EXTENT MANAGEMENT LOCAL;

   

ALTER DATABASE DATAFILE '/home/oracle_11/app/oradata/orcl/ts_myscott.dbf' AUTOEXTEND ON NEXT  10M MAXSIZE UNLIMITED;

ALTER DATABASE DATAFILE '/home/oracle_11/app/oradata/orcl/ts_myscott2.dbf' AUTOEXTEND ON NEXT  20M MAXSIZE UNLIMITED;

 

commit;

 

-- 02 创建方案 (创建用户)

CREATE USER MYSCOTT  PROFILE DEFAULT

    IDENTIFIED BY MYSCOTT DEFAULT TABLESPACE USERS

    ACCOUNT UNLOCK;

 

-- 资源和登录权限

GRANT RESOURCE TO MYSCOTT;

GRANT create session TO MYSCOTT;

 

 

-- 03 创建表

-- 创建部门表 并赋值

CREATE TABLE MYSCOTT.DEPT(

         DEPTNO     NUMBER(2) PRIMARY KEY,

        DNAME       VARCHAR2(14) NOT NULL,

        LOC          VARCHAR2(13)

)TABLESPACE ts_myscott;

 

INSERT INTO MYSCOTT.dept VALUES(10, 'ACCOUNTING', 'NEW YORK');

INSERT INTO MYSCOTT.dept VALUES(20, 'RESEARCH', 'DALLAS');

INSERT INTO MYSCOTT.dept VALUES(30, 'SALES', 'CHICAGO');

INSERT INTO MYSCOTT.dept VALUES(40, 'OPERATIONS', 'BOSTON');

 

commit;

 

-- 创建员工表 并赋值

CREATE TABLE MYSCOTT.EMP(

         EMPNO           NUMBER(4) constraint emp_empno_pk PRIMARY KEY,

         ENAME                   VARCHAR2(10) constraint emp_ename_notnull NOT NULL,

         JOB              VARCHAR2(9),

         MGR                     NUMBER(4),

         HIREDATE         DATE,

         SAL               NUMBER(7,2) constraint emp_sal_check check (SAL>0),

         COMM                  NUMBER(7,2),

         DEPTNO           NUMBER(2) constraint emp_deptno_fk references MYSCOTT.dept(deptno)

)TABLESPACE ts_myscott;

 

--创建索引 在新的表空间上

CREATE  INDEX MYSCOTT.IX_CAtbAuditOperInfo_OT ON MYSCOTT.EMP(ENAME) TABLESPACE ts_myscott2;

 

 

INSERT INTO MYSCOTT.EMP VALUES(7369, 'SMITH', 'CLERK', 7902, '17-12-80', 800, NULL, 20);

INSERT INTO MYSCOTT.EMP VALUES(7499, 'ALLEN', 'SALESMAN', 7698, '20-2 -81', 1600, 300, 30);

INSERT INTO MYSCOTT.EMP VALUES(7521, 'WARD', 'SALESMAN', 7698, '22-2 -81', 1250, 500, 30);

 

INSERT INTO MYSCOTT.EMP VALUES(7566, 'JONES', 'MANAGER', 7839, '02-4 -81', 2975, NULL, 20);

INSERT INTO MYSCOTT.EMP VALUES(7654, 'MARTIN', 'SALESMAN', 7698, '28-9 -81', 1250, 1400, 30);

INSERT INTO MYSCOTT.EMP VALUES(7698, 'BLAKE', 'MANAGER', 7839, '01-5 -81', 2850, NULL, 30);

 

INSERT INTO MYSCOTT.EMP VALUES(7782, 'CLARK', 'MANAGER', 7839, '09-6 -81', 2450, NULL, 10);

INSERT INTO MYSCOTT.EMP VALUES(7788, 'SCOTT', 'ANALYST', 7566, '19-4 -87', 3000, NULL, 20);

INSERT INTO MYSCOTT.EMP VALUES(7839, 'KING', 'PRESIDENT', NULL, '17-11-81', 5000, NULL, 10);

 

INSERT INTO MYSCOTT.EMP VALUES(7844, 'TURNER', 'SALESMAN', 7698, '08-9 -81', 1500, 0, 30);

INSERT INTO MYSCOTT.EMP VALUES(7876, 'ADAMS', 'CLERK', 7788, '23-5 -87', 1100, NULL, 20);

INSERT INTO MYSCOTT.EMP VALUES(7900, 'JAMES', 'CLERK', 7698, '03-12-81', 950, NULL, 30);

 

INSERT INTO MYSCOTT.EMP VALUES(7902, 'FORD', 'ANALYST', 7566, '03-12-81', 3000, NULL, 20);

INSERT INTO MYSCOTT.EMP VALUES(7934, 'MILLER', 'CLERK', 7782, '23-1 -82', 1300, NULL, 10);

 

commit;

 

-- 创建工资级别表 并赋值

CREATE TABLE MYSCOTT.SALGRADE(

        GRADE             NUMBER,

        LOSAL           NUMBER,

        HISAL           NUMBER

)TABLESPACE ts_myscott;

 

INSERT INTO MYSCOTT.SALGRADE VALUES(1, 700, 1200);

INSERT INTO MYSCOTT.SALGRADE VALUES(2, 1201, 1400);

INSERT INTO MYSCOTT.SALGRADE VALUES(3, 1401, 2000);

INSERT INTO MYSCOTT.SALGRADE VALUES(4, 2001, 3000);

INSERT INTO MYSCOTT.SALGRADE VALUES(5, 3001, 9999);

commit;

 

--创建奖金表

CREATE TABLE MYSCOTT.BONUS(

         ENAME      VARCHAR2(10),

        JOB       VARCHAR2(9),

        SAL             NUMBER,

        COMM      NUMBER

)TABLESPACE ts_myscott;

 

------停止-----

-- 04创建新用户方案   通过MYSCOTTUSER1来访问数据库, 权限配置演示 

CREATE USER "MYSCOTTUSER1"  PROFILE "DEFAULT" IDENTIFIED BY "123456" DEFAULT TABLESPACE "USERS" ACCOUNT UNLOCK;

GRANT "CONNECT" TO "MYSCOTTUSER1";

GRANT SELECT ANY TABLE TO "MYSCOTTUSER1";

 

GRANT DELETE ON MYSCOTT.DEPT TO "MYSCOTTUSER1";

GRANT INSERT ON MYSCOTT.DEPT TO "MYSCOTTUSER1";

GRANT UPDATE ON MYSCOTT.DEPT TO "MYSCOTTUSER1";

 

GRANT DELETE ON MYSCOTT.EMP TO "MYSCOTTUSER1";

GRANT INSERT ON MYSCOTT.EMP TO "MYSCOTTUSER1";

GRANT UPDATE ON MYSCOTT.EMP TO "MYSCOTTUSER1";

 

commit;

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

涂作权的博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值