關于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;
作者:JYRoy