最近业务需要给表添加索引,因为数据量很大时,查询效率很低;老大建议使用索引; 之前总结的时候将索引没有记录,当然啦,也怪笔者基础薄弱,不管了,慢慢进步嘛,好了进入正题吧!

首先准备工作,先建两个临时表,后边操作会用到;

--建临时学生表
create table temp_student(
id number,
name varchar2(20),
sex char(2),
age number,
class varchar2(20),
userId number
);
comment on table temp_student is '临时学生表';
comment on column temp_student.id is 'ID';
comment on column temp_student.name is '姓名';
comment on column temp_student.sex is '性别';
comment on column temp_student.age is '年龄';
comment on column temp_student.class is '班级';
comment on column temp_student.userId is '临时人员ID';
--建临时人员表
create table temp_user(
id number,
name varchar2(20),
age number,
sex char(2)
);
comment on table temp_user is '临时人员表';
comment on column temp_user.id is 'ID';
comment on column temp_user.name is '姓名';
comment on column temp_user.age is '年龄';
comment on column temp_user.sex is '性别';

下边是常用的操作,这里我暂时总结八点吧,吉利数字,嘎嘎!后边有需要继续总结,在这里将表数据的增删改没有总结,因为太简单了,在这里笔者认为是占地方,所以就免了,如果大家对表数据的增删改都不熟悉,那这篇文章对您暂时还不太适合,当以后熟悉了再来看看;

--
--查询表(pl/sql中可修改)
select * from temp_student for update;
select * from temp_user for update; --
--删除表
drop table temp_student;
drop table temp_user; --
--添加字段
alter table temp_student add join_date date;
comment on column temp_student.join_date is '入学时间';
--修改字段
alter table temp_student modify(class varchar2(200));
--重命名字段
alter table temp_student rename column join_date to join;
--重命名表
rename temp_student to t_student;
--删除字段
alter table t_student drop column join; --
--建主键
alter table temp_student add primary key (id);
alter table temp_user add primary key(id);
--建外键
alter table temp_student add constraint userKey foreign key(userId) references temp_user(id);
--撤销主键
alter table temp_student drop primary key;
--撤销外键
alter table temp_student drop constraint userKey; --
--给表建立公共别名
create public synonym t_student for temp_student;
create public synonym t_user for temp_user; --
--授权给指定角色权限
grant select,insert,update on sys.temp_student to bepcde,bepopr;
--收回给指定角色权限
revoke select,insert,update on sys.temp_student from bepcde,bepopr; --7
--建序列
create sequence t_student_seq
minvalue 1 --初始序号为1
maxvalue 9999999999999999 --最大序号,这里也可以设置
start with 1 --从1开始计算
increment by 1 --每次增1
cache 30 --缓存20个
cycle; --//循环
--删除序列
drop sequence t_student_seq;
--查询下一个序列号
select t_student_seq.nextval from dual; -- --
--创建索引
create index id_a on t_student(name);
--删除索引
drop index id_a;

如果朋友们发现那里有疑问或者问题,请指出来,谢谢!

oracle对表常用的操作的更多相关文章

  1. Oracle对表解锁的操作

    1.查出被锁的表 SELECT  lpad(' ',decode(l.xidusn ,0,3,0))||l.oracle_username User_name, o.owner,o.object_na ...

  2. Oracle手边常用命令及操作语句

    Oracle手边常用命令及操作语句 作者:白宁超 时间:2016年3月4日11:24:08 摘要:日常使用oracle数据库过程中,常用脚本命令莫不是用户和密码.表空间.多表联合.执行语句等常规操作. ...

  3. Oracle 对表的基本CURD操作

    Oracle对表的基本Curd操作: 样式表:        接下来对这张(表明:Stud)表进行Curd操作(请看面SQL代码) 增加新的字段列:alter table Stud add(heigh ...

  4. Oracle对表空间、用户、用户权限的操作

    一.对表空间的操作 1.创建表空间(create tablespace) -- 'hpdb_tablespace' 指定表空间名称 -- 'e:\hpdb.dbf' 指定表空间数据文件名称 -- si ...

  5. Oracle基本常用命令

    一.ORACLE的启动和关闭 1.在单机环境下 要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下 su - oracle a.启动ORACLE系统 oracle>svrmgrl ...

  6. Oracle数据库常用Sql语句大全

    一,数据控制语句 (DML) 部分 1.INSERT  (往数据表里插入记录的语句) INSERT INTO 表名(字段名1, 字段名2, ……) VALUES ( 值1, 值2, ……); INSE ...

  7. ORACLE 11GR2常用命令

    一.ORACLE的启动和关闭 1.在单机环境下 要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下 su - oracle a.启动ORACLE系统 oracle>svrmgrl ...

  8. Oracle手边常用70则脚本知识汇总

    Oracle手边常用70则脚本知识汇总 作者:白宁超 时间:2016年3月4日13:58:36 摘要: 日常使用oracle数据库过程中,常用脚本命令莫不是用户和密码.表空间.多表联合.执行语句等常规 ...

  9. 转--Oracle 审计和测试操作

    http://blog.itpub.net/21605631/viewspace-759640/转 Oracle 审计和测试操作 :: 分类: Linux 1.1 相关参数 AUDIT_SYS_OPE ...

随机推荐

  1. BZOJ2694 Lcm 【莫比乌斯反演】

    BZOJ2694 Lcm Description Input 一个正整数T表示数据组数 接下来T行 每行两个正整数 表示N.M Output T行 每行一个整数 表示第i组数据的结果 Sample I ...

  2. .NET Core/Framework 创建委托以大幅度提高反射调用的性能

    都知道反射伤性能,但不得不反射的时候又怎么办呢?当真的被问题逼迫的时候还是能找到解决办法的. 为反射得到的方法创建一个委托,此后调用此委托将能够提高近乎直接调用方法本身的性能.(当然 Emit 也能够 ...

  3. 迫不及待地体验了一把 C#8.0 中的可空引用类型(Nullable Reference)

    在我之前的一篇博客 NullReferenceException,就不应该存在! 中,我吐槽了 C# 中 null 的弊端以及避免 null 的方法:事实上这本都是现代高级语言中极力推崇的做法.Kot ...

  4. My Test about Mat

    一.创建Mat >Mat a = cv::Mat(2,2,CV_32S,1); output:  [1,1; 1,1] >Mat a = cv::Mat(2,2,CV_32SC3,1); ...

  5. flask第十五篇——Response

    从这一节开始,我就要开始讲关于模板的知识了.先来学习一下Response的相关知识. 所有返回前台的内容其实都应该是Response的对象或者其子类,我们看到如果返回的是字符串直接可以写成return ...

  6. drone 学习五 集成gitlab 配置以及简单测试

    备注: 使用docker-compose  进行安装 同时集成gitlab,预备环境 docker  docker-compose  gitlab 1. docker-compose version: ...

  7. laravel的学习历程

    首要,表明态度:PHP是世界上最佳的言语.(梗) laravel说是php将来,形似不假. 最开端触摸的是thinkphp,格外喜爱她的分层,文档格外完全,阅读起来没任何妨碍. 比较laravel,我 ...

  8. IIS7、IIS7.5中应用程序池最优配置方案

    https://www.cnblogs.com/xinaixia/p/5945678.html 找到Web站点对应的应用程序池,“应用程序池” → 找到对应的“应用程序池” → 右键“高级设置...” ...

  9. UI异常

    为什么chaneTab调用后,这个Tab都消失了? 因为li和table都用同一个ID所以,其中有一个步骤是清空表:$("#XXid").remove,连带着把那个li(tab)也 ...

  10. centos下svn的主要常用命令(解决商城系统添加的文件无法自动更新至svn服务器)

    问题描述: 在商城中通过网页上传的png文件无法自动添加到版本库中. 查找过程: 通过程序分析,增加的主要是数据文件,主要分布在data目录中. svn list /home/ggg --depth= ...