oracle对表常用的操作
最近业务需要给表添加索引,因为数据量很大时,查询效率很低;老大建议使用索引; 之前总结的时候将索引没有记录,当然啦,也怪笔者基础薄弱,不管了,慢慢进步嘛,好了进入正题吧!
首先准备工作,先建两个临时表,后边操作会用到;
--建临时学生表
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对表常用的操作的更多相关文章
- Oracle对表解锁的操作
1.查出被锁的表 SELECT lpad(' ',decode(l.xidusn ,0,3,0))||l.oracle_username User_name, o.owner,o.object_na ...
- Oracle手边常用命令及操作语句
Oracle手边常用命令及操作语句 作者:白宁超 时间:2016年3月4日11:24:08 摘要:日常使用oracle数据库过程中,常用脚本命令莫不是用户和密码.表空间.多表联合.执行语句等常规操作. ...
- Oracle 对表的基本CURD操作
Oracle对表的基本Curd操作: 样式表: 接下来对这张(表明:Stud)表进行Curd操作(请看面SQL代码) 增加新的字段列:alter table Stud add(heigh ...
- Oracle对表空间、用户、用户权限的操作
一.对表空间的操作 1.创建表空间(create tablespace) -- 'hpdb_tablespace' 指定表空间名称 -- 'e:\hpdb.dbf' 指定表空间数据文件名称 -- si ...
- Oracle基本常用命令
一.ORACLE的启动和关闭 1.在单机环境下 要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下 su - oracle a.启动ORACLE系统 oracle>svrmgrl ...
- Oracle数据库常用Sql语句大全
一,数据控制语句 (DML) 部分 1.INSERT (往数据表里插入记录的语句) INSERT INTO 表名(字段名1, 字段名2, ……) VALUES ( 值1, 值2, ……); INSE ...
- ORACLE 11GR2常用命令
一.ORACLE的启动和关闭 1.在单机环境下 要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下 su - oracle a.启动ORACLE系统 oracle>svrmgrl ...
- Oracle手边常用70则脚本知识汇总
Oracle手边常用70则脚本知识汇总 作者:白宁超 时间:2016年3月4日13:58:36 摘要: 日常使用oracle数据库过程中,常用脚本命令莫不是用户和密码.表空间.多表联合.执行语句等常规 ...
- 转--Oracle 审计和测试操作
http://blog.itpub.net/21605631/viewspace-759640/转 Oracle 审计和测试操作 :: 分类: Linux 1.1 相关参数 AUDIT_SYS_OPE ...
随机推荐
- html5大纲算法(目录树)
看了<CSS那些事儿>我一直遵循着给每个板块写一个h标签,并保持层次,比如导航条.焦点图我都写了一个缩进隐藏的h标签.这种规范一般人根本看不出来,即使是行内的大多数人也觉得没有必要.可是我 ...
- ASP.NET Core 中的SEO优化(2):中间件中渲染Razor视图
前言 上一篇文章<ASP.NET Core 中的SEO优化(1):中间件实现服务端静态化缓存>中介绍了中间件的使用方法.以及使用中间件实现服务端静态化缓存的功能.本系列文章的这些技巧都是我 ...
- 《selenium2 python 自动化测试实战》(11)——selenium安装版本
先和大家说一下selenium环境的问题,大家可以在cmd里先看一下自己的selenium版本: 回车,就可以安装了. 本来想和大家说如何跳过验证码进行登录的,结果好多朋友加我问我环境配置的问题,所以 ...
- 「GXOI / GZOI2019」简要题解
「GXOI / GZOI2019」简要题解 LOJ#3083. 「GXOI / GZOI2019」与或和 https://loj.ac/problem/3083 题意:求一个矩阵的所有子矩阵的与和 和 ...
- MAC OS、Windows 、HTML,CSS,font-family:中文字体的英文名称
宋体 SimSun 黑体 SimHei 微软雅黑 Microsoft YaHei 微软正黑体 Microsoft JhengHei 新宋体 NSimSun 新细明体 PMingLiU 细明体 Ming ...
- Træfɪk 服务发现解决方案
Træfɪk is a modern HTTP reverse proxy and load balancer made to deploy microservices with ease. It s ...
- cocos2d js jsb XMLHttpRequest 中文乱码
1.首先讲下怎样使用XMLHttpRequest 下面所说的是在cocos2d-x 2.2.2 或者 2.3 版本号中. 首先要明确cocos2d js事实上分两个版本号,一个是html5的版本号,另 ...
- [LeetCode系列]子集枚举问题[无重复元素]
给定一组数(未排序), 求它们的所有组合可能. 如给定{1 2 3}, 返回: [ [] [1] [2] [3] [1 2] [1 3] [2 3] [1 2 3] ] 算法思路: 对数组排序, 从小 ...
- git clone遇到的[ssh: connect to host github.com port 22]
起因 在学习递归的时候,对汉诺塔小研究了一番,参考网上写了个demo,后面就想同步到github. 过程 这台电脑是新电脑,所以需要先本地生成ssh key:ssh-keygen -t rsa -C ...
- Type-C潮流下 如何衡量一款数据线好坏?
不少新一代手机开始支持Type-C接口,比如乐视.PPTV.努比亚Z11.小米4C和三星Note7等.和普通Micro USB相比,Type-C数据线因为正反插的关系对品质要求更高,不然随时有短路烧毁 ...