数据库常用操作
增加列:alter table tableName add columnName number(10);
增加列并设置默认值: alter table tableName add columnName number(10) default 0;
删除列:ALTER Table tableName DROP column columnName;
将某列数值置为null:alter table tableName modify columnName null;
修改列的类型:alter table tableName modify columnName number(12,3);
重命名列名称: alter table tableName rename column oldColumn to newColumn;
设置Primary key :ALTER TABLE tableName ADD CONSTRAINT 主键名
PRIMARY KEY (columnName)
更改主键,并设置index,tablespace :
alter table tableName
add constraint 主键名 primary key (columnName1,columnName2)
using index;
tablespace USERS
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
创建table并添加注释:
create table table1
(
name varchar(20) not null
);
tablespace USERS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
comment on column table1.name
is '名称';
创建序列:
create sequence sequenceName
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 20;
创建同义词:
prompt
prompt Creating synonym tableName
prompt =======================================
prompt
create or replace synonym tableName for tableName@DBLinkName
spool off
删除表(含表结构):drop table tableName
删除表数据:delete from tableName
更新列值: update tableName set columnName = columnValue,columnName2 = columnValue2 .....;
####MySqL
从模板表创建表:create table if not exists like old_table_name;
创建表:create table if not exists table_name
删除表:drop table if exists table_name
增加列:alter table tableName add columnName number(10);
增加列并设置默认值: alter table tableName add columnName number(10) default 0;
删除列:ALTER Table tableName DROP column columnName;
将某列数值置为null:alter table tableName modify columnName null;
修改列的类型:alter table tableName modify columnName number(12,3);
重命名列名称: alter table tableName rename column oldColumn to newColumn;
设置Primary key :ALTER TABLE tableName ADD CONSTRAINT 主键名
PRIMARY KEY (columnName)
更改主键,并设置index,tablespace :
alter table tableName
add constraint 主键名 primary key (columnName1,columnName2)
using index;
tablespace USERS
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
创建table并添加注释:
create table table1
(
name varchar(20) not null
);
tablespace USERS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
comment on column table1.name
is '名称';
创建序列:
create sequence sequenceName
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 20;
创建同义词:
prompt
prompt Creating synonym tableName
prompt =======================================
prompt
create or replace synonym tableName for tableName@DBLinkName
spool off
删除表(含表结构):drop table tableName
删除表数据:delete from tableName
更新列值: update tableName set columnName = columnValue,columnName2 = columnValue2 .....;
####MySqL
从模板表创建表:create table if not exists like old_table_name;
创建表:create table if not exists table_name
删除表:drop table if exists table_name