createtablespace itheima
datafile 'c:\itheima.dbf'
size 100m
autoextend onnext10m;--删除表空间droptablespace itheima;
创建用户
createuser itheima
identified by itheima
defaulttablespace itheima;
给用户授权
--oracle数据库中常用角色connect--连接角色,基本角色
resource--开发者角色
dba--超级管理员角色--给itheima用户授予dba角色grant dba to itheima;---切换到itheima用户下
修改表结构
--添加一列altertable person add(gender number(1));--修改列类型altertable person modify gender char(1);--修改列名称altertable person renamecolumn gender to sex;--删除一列altertable person dropcolumn sex;
数据的增删改
---查询表中记录select*from person;----添加一条记录insertinto person (pid, pname)values(1,'小明');commit;----修改一条记录update person set pname ='小马'where pid =1;commit;----三个删除--删除表中全部记录deletefrom person;--删除表结构droptable person;--先删除表,再次创建表。效果等同于删除表中全部记录。--在数据量大的情况下,尤其在表中带有索引的情况下,该操作效率高。--索引可以提供查询效率,但是会影响增删改效率。truncatetable person;
序列的使用
----序列不真的属于任何一张表,但是可以逻辑和表做绑定。----序列:默认从1开始,依次递增,主要用来给主键赋值使用。----dual:虚表,只是为了补全语法,没有任何意义。create sequence s_person;select s_person.nextval from dual;----添加一条记录insertinto person (pid, pname)values(s_person.nextval,'小明');commit;select*from person;