建表空间
建用户
授权
Grant Connect,Resource,DBA to UserName;
创建表
create table TZFXB.F02_KEYPOINTS
(
ID NUMBER(10) not null,
TFBH VARCHAR2(6 CHAR),
RQSJ DATE,
JD NUMBER,
WD NUMBER,
KTYPE VARCHAR2(3 CHAR),
TYPE VARCHAR2(3 CHAR)
)
tablespace TZFXB
--指定数据块中必须保留的最小空闲空间
pctfree 10
--访问数据库的事务数
initrans 1
--最大事务数
maxtrans 255
--存储参数
storage
(
--为表指定分配的第一个盘区大小
initial 3520K
--指定定存储表中的数据分配的第二个盘区大小
next 320K
--指定允许为表中的数据所分配的最小盘区数目。
minextents 1
maxextents unlimited
);
--不会被记录到重做日志文件中
nologging;
自增长
prompt
prompt Creating sequence A02_STRONG_RECSMS_SMSID_SEQ
prompt =============================================
prompt
create sequence A02_STRONG_RECSMS_SMSID_SEQ
minvalue 1
maxvalue 999999999999999999999999
start with 1
increment by 1
cache 20;
prompt
prompt Creating trigger A02_STRONG_RECSMS_SMSID_TRIG
prompt =============================================
prompt
CREATE OR REPLACE TRIGGER A02_Strong_RECSMS_SMSID_TRIG BEFORE INSERT OR UPDATE ON A02_Strong_RECSMS
FOR EACH ROW
DECLARE
v_newVal NUMBER(12) := 0;
v_incval NUMBER(12) := 0;
BEGIN
IF INSERTING AND :new.SMSID IS NULL THEN
SELECT A02_Strong_RECSMS_SMSID_SEQ.NEXTVAL INTO v_newVal FROM DUAL;
-- If this is the first time this table have been inserted into (sequence == 1)
IF v_newVal = 1 THEN
--get the max indentity value from the table
SELECT NVL(max(SMSID),0) INTO v_newVal FROM A02_Strong_RECSMS;
v_newVal := v_newVal + 1;
--set the sequence to that value
LOOP
EXIT WHEN v_incval>=v_newVal;
SELECT A02_Strong_RECSMS_SMSID_SEQ.nextval INTO v_incval FROM dual;
END LOOP;
END IF;
-- assign the value from the sequence to emulate the identity column
:new.SMSID := v_newVal;
END IF;
END;
/
修改表
增加列
alter table A add(age number(2));
删除单列
alter table A drop column age;
删除多表
alter table A drop (age,sex);
更新字段
alter table A modify job number(20);
更改表的存储空间与存储参数
alter table A move tablespace user
pctfree 30
pctused 50;
删除表
drop table A
删除表的同时删除引用这个表的视图、约束、触发器等
drop table A cascade constraionts;
还原被 删除的表
flashback table A to before drop;
改表为只读
alter table A read only;
改表为读写
alter table A read write;
授权现有用户给现有空间
alter user tzfxb quota unlimited on tzfxb