Advertisement

数据库创建表操作规范注意事项

阅读量:

数据库创建表操作规范注意事项

该系统中所有表被用于创建该用户。创建表格时使用的存储空间设为主键位置,并配置了外键字段及索引也被配置为TBS_IDX类型。例如如何构建该表格的详细说明如下:

-- Create table

createtable UCR_SHOP.TEST_LINDW

(

ORG_ID_TEST NUMBER ( 8 ) notnull

)

tablespace TBS_DAT

pctfree 10

initrans 1

maxtrans 255

storage

(

initial 256 K

next 1 M

minextents 1

maxextentsunlimited

pctincrease 0

);

2)需要将新建的表相关权限授予uop_shop用户,参考如下语句:

grantinsert , delete , select , updateon UCR_SHOP. tets_tablename to uop_shop;

3)创建表对应同义词,参考如下语句:

create public synonym test_tablename for UCR_SHOP.test_tablename;

注意:如果涉及构建表格(即Build Table),则需明确列出具体步骤;建议待完成表格构建工作后将授权及创建同义词的相关指令安排至后方处理,请参考杰哥提供的Build Table SQL示例:修改后的代码如下

-- Create table

create table UCR_SHOP.ECPS_SHUA_COUPONS_GROUP

(

COUPONS_GROUP_ID VARCHAR2(32) not null,

COUPONS_GROUP_NAME VARCHAR2(256),

COUPONS_GROUP_STYLE VARCHAR2(16),

COUPONS_GROUP_PROBABILITY INTEGER,

COUPONS_GROUP_DESC VARCHAR2(1024)

)

tablespace TBS_DAT

pctfree 10

initrans 1

maxtrans 255

storage

(

initial 10M

next 10M

minextents 1

maxextents unlimited

pctincrease 0

);

-- Add comments to the table

comment on table UCR_SHOP.ECPS_SHUA_COUPONS_GROUP

is ' 卡劵大类 ';

-- Add comments to the columns

comment on column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPONS_GROUP_ID

is ' 卡券大类 ID';

comment on column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPONS_GROUP_NAME

is ' 卡券大类名称 ';

comment on column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPONS_GROUP_STYLE

is ' 卡券展示 ';

discuss the column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPpons_GROUP_PROBABILITY

is ' 中奖概率 ';

comment on column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPONS_GROUP_DESC

is ' 描述 ';

-- Create/Recreate primary, unique and foreign key constraints 主键

alter table UCR_SHOP.ECPS_SHUA_COUPONS_GROUP

add constraint PK_ECPS_SHUA_COUPONS_GROUP primary key (COUPONS_GROUP_ID)

using index

tablespace TBS_IDX

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 10M

next 10M

minextents 1

maxextents unlimited

pctincrease 0

);

------ 权限授予 uop_shop 用户

授予该表ECPS_SHUA_COUPONS_GROUP上插入、删除、选择和更新权限

------ 创建表对应同义词

指定为公有同义词的ECPS_SHUA_COUPpons_GROUP表名为UCR_SHOP.ECPS.SHUAA.COUpONs.GROUP;

4)创建序列,用UOP_SHOP用户,参考如下语句:

CREATE SEQUENCE UOP_SHOP.test_tablename

minvalue 1

maxvalue 999999999999999999

start with 1

increment by 1

cache 20;

5)创建索引,用UCR_SHOP用户,参考如下语句:

create INDEX_NAME index UCR_SHOP.test_tablename(PRIZE_VALID_END)

tablespace TBS_IDX

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 10M

next 10M

minextents 1

maxextents unlimited

pctincrease 0

);

6)insertinto、update用ucr_shop用户,参考如下语句:

执行插入操作于UCR_Shop数据库中的测试表名称(PAYCHNNL、INNER_MER、INTERFACETYPE、OFFLINEFLAG及REF_ID)

values ('WEIXINPAY', '888073157340006', 'app', '1', '4');

update ucr_shop.test_tablename set ROYALTY = '1' ,PAY_PARTNERID = '888073157340006';

7)添加主键用UCR_SHOP用户,参考如下语句:

alter table UCR_SHOP.test_tablename

add constraint TF_R_HOTSEARCH_ID primary key (HOTSEARCH_ID)

using index

tablespace TBS_IDX

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 10M

next 10M

minextents 1

maxextents unlimited

pctincrease 0

);

提交的DB变更脚本名称统一命名为'需求名+姓名.txt/sql'的形式发送,请参考例如:shua-优化周杰.sql

数据库创建表操作规范注意事项

在UCR_SHOPS系统中为该用户创建全部表。通过主键、外键以及索引等字段的配置实现TBS_IDX的空间分配。例如如何操作

-- Create table

createtable UCR_SHOP.TEST_LINDW

(

ORG_ID_TEST NUMBER ( 8 ) notnull

)

tablespace TBS_DAT

pctfree 10

initrans 1

maxtrans 255

storage

(

initial 256 K

next 1 M

minextents 1

maxextentsunlimited

pctincrease 0

);

2)需要将新建的表相关权限授予uop_shop用户,参考如下语句:

grantinsert , delete , select , updateon UCR_SHOP. tets_tablename to uop_shop;

3)创建表对应同义词,参考如下语句:

create public synonym test_tablename for UCR_SHOP.test_tablename;

在构建数据库表时,默认应遵循以下三个步骤:确定字段名称与数据类型、设置约束条件与索引结构以及定义默认值与唯一性限制;建议将所有权限设置及同义词相关语句安排在创建完整数据库表之后执行

-- Create table

create table UCR_SHOP.ECPS_SHUA_COUPONS_GROUP

(

COUPONS_GROUP_ID VARCHAR2(32) not null,

COUPONS_GROUP_NAME VARCHAR2(256),

COUPONS_GROUP_STYLE VARCHAR2(16),

COUPONS_GROUP_PROBABILITY INTEGER,

COUPONS_GROUP_DESC VARCHAR2(1024)

)

tablespace TBS_DAT

pctfree 10

initrans 1

maxtrans 255

storage

(

initial 10M

next 10M

minextents 1

maxextents unlimited

pctincrease 0

);

-- Add comments to the table

comment on table UCR_SHOP.ECPS_SHUA_COUPONS_GROUP

is ' 卡劵大类 ';

-- Add comments to the columns

comment on column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPONS_GROUP_ID

is ' 卡券大类 ID';

comment on column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPONS_GROUP_NAME

is ' 卡券大类名称 ';

comment on column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPONS_GROUP_STYLE

is ' 卡券展示 ';

provide a detailed analysis of the column UCR SHOP ECPS Shua Coupons Group COUpons Group Probability

is ' 中奖概率 ';

comment on column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPONS_GROUP_DESC

is ' 描述 ';

-- Create/Recreate primary, unique and foreign key constraints 主键

alter table UCR_SHOP.ECPS_SHUA_COUPONS_GROUP

add constraint PK_ECPS_SHUA_COUPONS_GROUP primary key (COUPONS_GROUP_ID)

using index

tablespace TBS_IDX

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 10M

next 10M

minextents 1

maxextents unlimited

pctincrease 0

);

------ 权限授予 uop_shop 用户

创建包含插入、删除、选择和更新操作的语句并将其应用于指定表以写入目标库

------ 创建表对应同义词

定义为公共同义词 ECPS_SHUA_COUPONS_GROUP 用于指向 UCRSHOPS 中的 ECPS_SHUA_COUPponsGROUP

4)创建序列,用UOP_SHOP用户,参考如下语句:

CREATE SEQUENCE UOP_SHOP.test_tablename

minvalue 1

maxvalue 999999999999999999

start with 1

increment by 1

cache 20;

5)创建索引,用UCR_SHOP用户,参考如下语句:

create INDEX_NAME index UCR_SHOP.test_tablename(PRIZE_VALID_END)

tablespace TBS_IDX

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 10M

next 10M

minextents 1

maxextents unlimited

pctincrease 0

);

6)insertinto、update用ucr_shop用户,参考如下语句:

Enter the specified payment channel code and other required details into the test table name ucr_shop.test_tablename.

values ('WEIXINPAY', '888073157340006', 'app', '1', '4');

update ucr_shop.test_tablename set ROYALTY = '1' ,PAY_PARTNERID = '888073157340006';

7)添加主键用UCR_SHOP用户,参考如下语句:

alter table UCR_SHOP.test_tablename

add constraint TF_R_HOTSEARCH_ID primary key (HOTSEARCH_ID)

using index

tablespace TBS_IDX

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 10M

next 10M

minextents 1

maxextents unlimited

pctincrease 0

);

提交的DB变更文件名称统一采用"需求名+姓名.txt/sql"的形式发送。例如:shua-优化周杰.sql

数据库创建表操作规范注意事项

在UCR_SHOP数据库中对全部表格进行创建操作以实现该用户的管理需求。每个新建的表均分配了TBS_DAT作为主键字段,并配置了相应的外键关系和索引结构以保证数据的一致性和完整性。举个例子说明具体的创建过程

-- Create table

createtable UCR_SHOP.TEST_LINDW

(

ORG_ID_TEST NUMBER ( 8 ) notnull

)

tablespace TBS_DAT

pctfree 10

initrans 1

maxtrans 255

storage

(

initial 256 K

next 1 M

minextents 1

maxextentsunlimited

pctincrease 0

);

2)需要将新建的表相关权限授予uop_shop用户,参考如下语句:

grantinsert , delete , select , updateon UCR_SHOP. tets_tablename to uop_shop;

3)创建表对应同义词,参考如下语句:

create public synonym test_tablename for UCR_SHOP.test_tablename;

若涉及建表,则通常包含三个步骤:数据定义、数据约束以及数据类型配置等核心要素的完整设置。建议在完成建表操作后集中处理权限设置与同义词映射相关的语句。如以杰哥的建表SQL为例:修改代码时需特别注意对数据库结构进行完善的同时也要确保所有字段的相关性与一致性得到充分验证。优化代码是一个系统性工程需要从多个层面入手包括但不限于性能调优功能扩展以及安全性增强等方面进行综合考量以确保最终交付成果能够满足实际应用需求

-- Create table

create table UCR_SHOP.ECPS_SHUA_COUPONS_GROUP

(

COUPONS_GROUP_ID VARCHAR2(32) not null,

COUPONS_GROUP_NAME VARCHAR2(256),

COUPONS_GROUP_STYLE VARCHAR2(16),

COUPONS_GROUP_PROBABILITY INTEGER,

COUPONS_GROUP_DESC VARCHAR2(1024)

)

tablespace TBS_DAT

pctfree 10

initrans 1

maxtrans 255

storage

(

initial 10M

next 10M

minextents 1

maxextents unlimited

pctincrease 0

);

-- Add comments to the table

comment on table UCR_SHOP.ECPS_SHUA_COUPONS_GROUP

is ' 卡劵大类 ';

-- Add comments to the columns

comment on column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPONS_GROUP_ID

is ' 卡券大类 ID';

comment on column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPONS_GROUP_NAME

is ' 卡券大类名称 ';

comment on column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPONS_GROUP_STYLE

is ' 卡券展示 ';

The comment category within the UCR SHOPS falls under the ECPS Shua Coupons Group, with a focus on the COUpons Group Probability

is ' 中奖概率 ';

comment on column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPONS_GROUP_DESC

is ' 描述 ';

-- Create/Recreate primary, unique and foreign key constraints 主键

alter table UCR_SHOP.ECPS_SHUA_COUPONS_GROUP

add constraint PK_ECPS_SHUA_COUPONS_GROUP primary key (COUPONS_GROUP_ID)

using index

tablespace TBS_IDX

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 10M

next 10M

minextents 1

maxextents unlimited

pctincrease 0

);

------ 权限授予 uop_shop 用户

将插入、删除、查询和更新操作授予UCR_SHOP.ECPS_SHUA_COUPONS_GROUP表,并将其结果存储到uop_shop表中

------ 创建表对应同义词

define a public alias ECPS_SHUA_COUPONS_GROUP as synonym of UCR SHOPS.ECPS SHUA COUpons GROUP.

4)创建序列,用UOP_SHOP用户,参考如下语句:

CREATE SEQUENCE UOP_SHOP.test_tablename

minvalue 1

maxvalue 999999999999999999

start with 1

increment by 1

cache 20;

5)创建索引,用UCR_SHOP用户,参考如下语句:

create INDEX_NAME index UCR_SHOP.test_tablename(PRIZE_VALID_END)

tablespace TBS_IDX

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 10M

next 10M

minextents 1

maxextents unlimited

pctincrease 0

);

6)insertinto、update用ucr_shop用户,参考如下语句:

将数据插入到ucr_shop.test_tablename中的(PAYCHNNL, INNER_MER, INTERFACETYPE, OFFLINEFLAG, REF_ID)字段中

values ('WEIXINPAY', '888073157340006', 'app', '1', '4');

update ucr_shop.test_tablename set ROYALTY = '1' ,PAY_PARTNERID = '888073157340006';

7)添加主键用UCR_SHOP用户,参考如下语句:

alter table UCR_SHOP.test_tablename

add constraint TF_R_HOTSEARCH_ID primary key (HOTSEARCH_ID)

using index

tablespace TBS_IDX

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 10M

next 10M

minextents 1

maxextents unlimited

pctincrease 0

);

所有DB变更脚本名称都应按照"需求名+姓名.txt/sql"的方式命名后通过指定路径发送

数据库创建表操作规范注意事项

根据ucr_shop系统需求,在数据库中构建全部表结构以满足用户管理功能;其中每个表格均按照TBS_DAT方案进行设计,并配置主键字段作为核心存储单元;外键字段用于关联其他相关数据;同时在每个表格中添加必要索引字段以提升查询效率;具体实施方式可参考以下几种常见的建表方案及其配置方式

-- Create table

createtable UCR_SHOP.TEST_LINDW

(

ORG_ID_TEST NUMBER ( 8 ) notnull

)

tablespace TBS_DAT

pctfree 10

initrans 1

maxtrans 255

storage

(

initial 256 K

next 1 M

minextents 1

maxextentsunlimited

pctincrease 0

);

2)需要将新建的表相关权限授予uop_shop用户,参考如下语句:

grantinsert , delete , select , updateon UCR_SHOP. tets_tablename to uop_shop;

3)创建表对应同义词,参考如下语句:

create public synonym test_tablename for UCR_SHOP.test_tablename;

请确保所有字段都已定义好单位属性并指定单位属性类型后再执行此操作,请注意以下几点:

  1. 如果是要建立一张表,则必须包含至少三个步骤
  2. 建立数据库索引时请特别注意索引名称的选择
  3. 在执行创建约束命令前务必先定义约束类型
  4. 确保所有约束条件都已正确配置
  5. 在运行这些命令之前请确保系统有足够的权限
  6. 确保所选数据库已经连接到主存储引擎
  7. 避免同时打开多个数据库连接器以提高性能

-- Create table

create table UCR_SHOP.ECPS_SHUA_COUPONS_GROUP

(

COUPONS_GROUP_ID VARCHAR2(32) not null,

COUPONS_GROUP_NAME VARCHAR2(256),

COUPONS_GROUP_STYLE VARCHAR2(16),

COUPONS_GROUP_PROBABILITY INTEGER,

COUPONS_GROUP_DESC VARCHAR2(1024)

)

tablespace TBS_DAT

pctfree 10

initrans 1

maxtrans 255

storage

(

initial 10M

next 10M

minextents 1

maxextents unlimited

pctincrease 0

);

-- Add comments to the table

comment on table UCR_SHOP.ECPS_SHUA_COUPONS_GROUP

is ' 卡劵大类 ';

-- Add comments to the columns

comment on column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPONS_GROUP_ID

is ' 卡券大类 ID';

comment on column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPONS_GROUP_NAME

is ' 卡券大类名称 ';

comment on column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPONS_GROUP_STYLE

is ' 卡券展示 ';

review the column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPONS_GROUP_PROBABILITY

is ' 中奖概率 ';

comment on column UCR_SHOP.ECPS_SHUA_COUPONS_GROUP.COUPONS_GROUP_DESC

is ' 描述 ';

-- Create/Recreate primary, unique and foreign key constraints 主键

alter table UCR_SHOP.ECPS_SHUA_COUPONS_GROUP

add constraint PK_ECPS_SHUA_COUPONS_GROUP primary key (COUPONS_GROUP_ID)

using index

tablespace TBS_IDX

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 10M

next 10M

minextents 1

maxextents unlimited

pctincrease 0

);

------ 权限授予 uop_shop 用户

grant insert into, delete from, retrieve or fetch existing coupon group records from the UCR_SHOP.ECPS_SHUA_COUPONS_GROUP database to update the corresponding coupon group records in the uop_shop database.

------ 创建表对应同义词

define a public synonym ECPS_SHUA_COUPONS_GROUP as a reference to the coupon group UCR SHOPS.ECPS_SHUA_COUPONS_GROUP;

4)创建序列,用UOP_SHOP用户,参考如下语句:

CREATE SEQUENCE UOP_SHOP.test_tablename

minvalue 1

maxvalue 999999999999999999

start with 1

increment by 1

cache 20;

5)创建索引,用UCR_SHOP用户,参考如下语句:

create INDEX_NAME index UCR_SHOP.test_tablename(PRIZE_VALID_END)

tablespace TBS_IDX

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 10M

next 10M

minextents 1

maxextents unlimited

pctincrease 0

);

6)insertinto、update用ucr_shop用户,参考如下语句:

执行以下插入操作到ucr_shop中的辅助测试表中:PayerChannel, InnerMer, INTERFACETYPE, OFFLINEFLAG, REF_ID

values ('WEIXINPAY', '888073157340006', 'app', '1', '4');

update ucr_shop.test_tablename set ROYALTY = '1' ,PAY_PARTNERID = '888073157340006';

7)添加主键用UCR_SHOP用户,参考如下语句:

alter table UCR_SHOP.test_tablename

add constraint TF_R_HOTSEARCH_ID primary key (HOTSEARCH_ID)

using index

tablespace TBS_IDX

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 10M

next 10M

minextents 1

maxextents unlimited

pctincrease 0

);

所有DB变更操作对应的脚本文件名称必须遵循"需求名+操作者姓名.txt/sql"的规定,并在邮件中一并附上.

全部评论 (0)

还没有任何评论哟~