【Oracle数据库】创建、增删查改、复制表

16 篇文章 1 订阅
3 篇文章 0 订阅

数据类型

  • number:没有指定长度限制
  • varchar2(100):字符串类型,oracle特有的,最大长度4000,可变长度,把空字符串当作null处理。
  • varchar(100) : 字符串类型,sql标准,可以存储空字符串,oracle 建议使用varchar2 。
  • char(100) : 字符串类型,定长,例如存储字符串 ’ABC’, char(100) 使用100个字节,97个字节是空的,而varchar2 (100) 只使用3个字节,100只是指定了最大长度。
  • date:日期类型,sysdate 表示系统日期,默认格式15-04-21表示2021.4.15
  • long: 存储的是可变长字符串,最大长度限制是2GB。long: 存储的是可变长字符串,最大长度限制是2GB。
  • blob: 二进制大型对象(Binary Large Object), 最大为4G, 用来存储图片,文件,音乐等。
  • clob:字符大型对象(Character Large Object), 存储长的文本,最大为4G。
    新建用户TEST,并赋予权限Resource和connect参考,并用test用户进行下列操作管理员用户建的表,不能删除

创建表

create table 表名
(
 stname varchar2(10) not null ,		/* 不能为空 */
 stsex char(3),
 stid char(4)
 stgrade varchar(5) default '一年级'  /* 默认值为'一年级' */
);
create table table01
(
 stname varchar2(10) not null,
 stsex char(3),
 stid char(4),
 stgrade varchar(6) default '一年级'
);

查询表

  • 查看当前用户下的所有表

select * from user_table;
  • 查看表结构

select * from user_tab_cols where table_name = '大写用户名'
select * from user_tab_cols where table_name = 'TABLE01'

修改

  • 修改表名

alter table table01 rename to test01
  • 直接修改

select * from 表格名 for update;
select * from table01 for update;
  • 复制整个表(不复制约束)

create table 新表格名 as select * from 被复制的表格名;
create table table02 as select * from table01;
  • 复制部分数据

create table table04 as select * from table01 where stname = 'a';
create table2 as select 字段2,字段1 from1;		/*表2复制表1*/
/* 字段可1可多,用'*'可复制全部数据 */
create table table03 as select stname,stid,table01 from name,id;
  • 复制数据

insert into table05(stname,stsex)select stname,stsex from table01;
  • 添加列

alter table table01 add (stwy number(11));
  • 修改列名

alter table table01 rename column stwy to st_class;
  • 修改表格结构

alter table table01 modify(stsex char(4),2);
  • 插入内容

insert into 表名 values(1的值,列2的值,...有多少列写多少值);
insert into table01 values('a1','男',14,'二年级')
  • 更新内容

update 表名 set 列名=新的值 where 条件;
update table01 set stid=13 where sname = 'a1'

查看

  • 查看创建表

select * from user_tab_colums where table_name='TABLE01';
  • 添加备注

/*--给表添加备注*/
comment on table 表名 is '学生信息表';

/*--给表的字段添加备注*/
comment on column 表名.字段名 is '学生编号';

删除

  • 删除表结构(列)

alter table table01 add(sttel char(13));	/* 添加一列 */
alter table table01 drop column sttel;		/* 删除 */
  • 删除内容(能回滚)


delete from table03 where stname = 'a1';

  • 删除内容(不能回滚)

truncate table table05;
  • 删除表

drop table table05;
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值