Oracle中的一些基本操作

  关于Oracle中的一些基本操作,包括表空间操作,用户操作,表操作

 1 --创建表空间
 2 create tablespace itheima
 3 datafile 'I:\oracle\table\itheima.dbf'
 4 size 100m
 5 autoextend on
 6 next 10m;
 7 --删除表空间
 8 drop tablespace itheima;
 9 
10 --创建用户
11 create user itheima
12 identified by itheima
13 default tablespace itheima;
14 
15 --给用户授权
16 --oracle数据库中常用角色
17 connect --连接角色
18 resource --开发者角色
19 dba --超级管理员角色
20 
21 --给itheima角色授予dba角色
22 grant dba to itheima;
23 
24 --切换到itheima用户下
25 --session->logoff->logon
26 
27 --创建一个person表
28 create table person(
29        pid number(20),
30        pname varchar2(10)  
31 );
32 
33 
34 --修改表结构
35 --添加一列
36 alter table person add gender number(1);
37 --修改列的类型
38 alter table person modify gender char(1);
39 --修改列名称
40 alter table person rename column gender to sex;
41 --删除一列
42 alter table person drop column sex;
43 
44 --查询表中记录
45 select * from person;
46 --添加一条记录
47 insert into person (pid, pname) values (1, '小明');
48 commit;
49 --修改一条记录
50 update person set pname = '小马' where pid = 1;
51 commit;
52 
53 --三个删除
54 --删除表中全部记录
55 delete from person;
56 --删除表结构
57 drop table person;
58 --先删除表,再创建表
59 truncate table person;
60 
61 --序列,默认从1开始,依次递增,主要用来给主键赋值使用
62 --序列不真的属于一张表,但是可以逻辑和表做绑定
63 --dual:虚表,只是为了补全语法,没有任何意义
64 create sequence s_person;
65 select s_person.nextval from dual;
66 select s_person.currval from dual;
67 
68 --添加一条记录
69 insert into person (pid, pname) values (s_person.nextval, '小明');
70 commit;
71 select * from person;

猜你喜欢

转载自www.cnblogs.com/jyroy/p/11347847.html