数据库常用操作

数据库常用操作
增加列: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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值