文章摘要
这篇文章主要介绍了如何在数据库中创建带有时间分区的表`MY_TEST`,并对其分区策略、主键、注释、索引、权限和数据插入等进行了配置和说明。具体操作包括: 1. **表创建**:表`MY_TEST`包含`id`(主键)、`name`和`today`字段,`today`字段使用时间分区,按天进行分区。 2. **注释添加**:对表和字段添加了详细的注释,帮助理解表的结构和字段含义。 3. **索引创建**:在`id`字段上创建了优化索引,调整了索引参数以平衡性能和存储需求。 4. **权限管理**:授予了`DBVIEW`用户对表`MY_TEST`的 SELECT 权限。 5. **数据插入**:向表中插入了三条测试数据。 文章通过这些操作展示了数据库表创建、配置和管理的常见操作,适合初学者参考学习。
– Create table
create table MY_TEST
(
id NUMBER (12) not null,
name VARCHAR2 (12) not null,
today TIMESTAMP (6) default SYSDATE
)
partition by range (today) interval(numtodsinterval(1,’day’)) –月分区用month,年分区用year
(
partition P_20230411 values less than (TO_DATE(‘2023-04-12 00:00:00,”SYYYY-MM-DD HH24:MI:SS”))
tablespace TB_SAMS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
)
);
– – Add comments to the table
comment on table MY_TEST
is ‘测试表’;
Add comments to the columns
comment on column MY_TEST.id
is ‘主键id’;
comment on column MY_TEST.name
is ‘名称’;
comment on column MY_TEST.today
is ‘时间’;
create table MY_TEST
(
id NUMBER (12) not null,
name VARCHAR2 (12) not null,
today TIMESTAMP (6) default SYSDATE
)
partition by range (today) interval(numtodsinterval(1,’day’)) –月分区用month,年分区用year
(
partition P_20230411 values less than (TO_DATE(‘2023-04-12 00:00:00,”SYYYY-MM-DD HH24:MI:SS”))
tablespace TB_SAMS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
)
);
– – Add comments to the table
comment on table MY_TEST
is ‘测试表’;
Add comments to the columns
comment on column MY_TEST.id
is ‘主键id’;
comment on column MY_TEST.name
is ‘名称’;
comment on column MY_TEST.today
is ‘时间’;
– – Create/Recreate indexes
create index MY_TEST_INDEX on MY_TEST (id)
tablespace TB_SAMS
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);
– -Grant/Revoke object privileges
grant select on MY_TEST to DBVIEW;
INSERT INTO MY_TEST VALUES (1,’xxc1′,SYSDATE);
INSERT INTO MY_TEST VALUES (2,’xxc2′?SYSDATE+1);
INSERT INTO MY_TEST VAIUES (3,’xxc3′,SYSDATE+2) ;
© 版权声明
文章版权归作者所有,未经允许请勿转载。