进入超级管理员,运行下面命令 |
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 ALTER DATABASE DATAFILE 'F:/app/to-to/oradata/orcl/ts_myscott2.dbf' AUTOEXTEND ON NEXT commit; -- 02 CREATE USER MYSCOTT 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 COMM NUMBER(7,2), DEPTNO NUMBER(2) constraint emp_deptno_fk references MYSCOTT.dept(deptno) )TABLESPACE ts_myscott; --创建索引 CREATE INSERT INTO MYSCOTT.EMP VALUES(7369, 'SMITH', 'CLERK', 7902, '17-12月-80', INSERT INTO MYSCOTT.EMP VALUES(7499, 'ALLEN', 'SALESMAN', 7698, '20-2月 INSERT INTO MYSCOTT.EMP VALUES(7521, 'WARD', 'SALESMAN', 7698, '22-2月 INSERT INTO MYSCOTT.EMP VALUES(7566, 'JONES', 'MANAGER', 7839, '02-4月 INSERT INTO MYSCOTT.EMP VALUES(7654, 'MARTIN', 'SALESMAN', 7698, '28-9月 INSERT INTO MYSCOTT.EMP VALUES(7698, 'BLAKE', 'MANAGER', 7839, '01-5月 INSERT INTO MYSCOTT.EMP VALUES(7782, 'CLARK', 'MANAGER', 7839, '09-6月 INSERT INTO MYSCOTT.EMP VALUES(7788, 'SCOTT', 'ANALYST', 7566, '19-4月 INSERT INTO MYSCOTT.EMP VALUES(7839, 'KING', 'PRESIDENT', NULL, '17-11月-81', INSERT INTO MYSCOTT.EMP VALUES(7844, 'TURNER', 'SALESMAN', 7698, '08-9月 INSERT INTO MYSCOTT.EMP VALUES(7876, 'ADAMS', 'CLERK', 7788, '23-5月 INSERT INTO MYSCOTT.EMP VALUES(7900, 'JAMES', 'CLERK', 7698, '03-12月-81', INSERT INTO MYSCOTT.EMP VALUES(7902, 'FORD', 'ANALYST', 7566, '03-12月-81', INSERT INTO MYSCOTT.EMP VALUES(7934, 'MILLER', 'CLERK', 7782, '23-1月 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创建新用户方案 CREATE USER "MYSCOTTUSER1" 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 ALTER DATABASE DATAFILE '/home/oracle_11/app/oradata/orcl/ts_myscott2.dbf' AUTOEXTEND ON NEXT commit; -- 02 CREATE USER MYSCOTT 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 COMM NUMBER(7,2), DEPTNO NUMBER(2) constraint emp_deptno_fk references MYSCOTT.dept(deptno) )TABLESPACE ts_myscott; --创建索引 CREATE INSERT INTO MYSCOTT.EMP VALUES(7369, 'SMITH', 'CLERK', 7902, '17-12月-80', INSERT INTO MYSCOTT.EMP VALUES(7499, 'ALLEN', 'SALESMAN', 7698, '20-2月 INSERT INTO MYSCOTT.EMP VALUES(7521, 'WARD', 'SALESMAN', 7698, '22-2月 INSERT INTO MYSCOTT.EMP VALUES(7566, 'JONES', 'MANAGER', 7839, '02-4月 INSERT INTO MYSCOTT.EMP VALUES(7654, 'MARTIN', 'SALESMAN', 7698, '28-9月 INSERT INTO MYSCOTT.EMP VALUES(7698, 'BLAKE', 'MANAGER', 7839, '01-5月 INSERT INTO MYSCOTT.EMP VALUES(7782, 'CLARK', 'MANAGER', 7839, '09-6月 INSERT INTO MYSCOTT.EMP VALUES(7788, 'SCOTT', 'ANALYST', 7566, '19-4月 INSERT INTO MYSCOTT.EMP VALUES(7839, 'KING', 'PRESIDENT', NULL, '17-11月-81', INSERT INTO MYSCOTT.EMP VALUES(7844, 'TURNER', 'SALESMAN', 7698, '08-9月 INSERT INTO MYSCOTT.EMP VALUES(7876, 'ADAMS', 'CLERK', 7788, '23-5月 INSERT INTO MYSCOTT.EMP VALUES(7900, 'JAMES', 'CLERK', 7698, '03-12月-81', INSERT INTO MYSCOTT.EMP VALUES(7902, 'FORD', 'ANALYST', 7566, '03-12月-81', INSERT INTO MYSCOTT.EMP VALUES(7934, 'MILLER', 'CLERK', 7782, '23-1月 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创建新用户方案 CREATE USER "MYSCOTTUSER1" 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; |