oracle表空间基本命令,修改数据表结构基本命令,oracle数据
表空间基本命令
--创建表空间 初始化大小10M 自动增长5M 最大50M
create tablespace duan datafile 'F:\oracle\product\10.2.0\oradata\orcl\duan.dbf' size 10Mautoextend on next 5M maxsize 50M;
--查询表空间的地址和空间名称
select file_name,tablespace_name from dba_data_files order by file_name;
--创建multiple表空间,含有两个数据文件
create tablespace multiple_data datafile 'F:\oracle\product\10.2.0\oradata\orcl\multiple_01.dbf' size 5M ,
'F:\oracle\product\10.2.0\oradata\orcl\multiple_2.dbf' size 5M;
--查看所有表空间的信息
select tablespace_name,status,allocation_type from dba_tablespaces;
--查询每个用户的默认表空间
select user_id,username,default_tablespace from dba_users;
--修改数据库的默认表空间
alter database default tablespace duan;
--修改表空间名称
alter tablespace duan rename to duanxiangchao;
--删除表空间,仅删除表空间的记录
drop tablespace duan;
--删除表空间,包括数据文件
drop tablespace duan including contents and datafiles;
--利用命令修改数据表结构
--修改数据表结构的命令为 alter table
--为列重命名
alter table t_user rename column user_email to email;
--利用modify关键字,对列的属性进行修改 修改列长度时如果有记录长度大于新修改的长度,会报错
alter table t_user modify(user_name varchar2(25));
--oracle允许一次修改多个属性
alter table t_user modify(user_name varchar2(30),email varchar2(45));
--为表添加一列
alter table t_user add(remark varchar2(50));
--drop column 删除表中的某一列
alter table t_user drop column remark;
--alter对表本身属性进行修改
alter table t_user rename to my_user;
/*对于add和modify都无需添加column关键字,而drop需要。
因为修改一个表时,删除操作可能针对标的某些约束,所以必须添加column表示要删除的是某一个列*/
--删除数据库
drop table t_user;
--删除数据库,作用于约束
drop table t_user cascade constraints;
alter命令是用来改表结构 不是改数据的。属于DDL数据定义语言
以下的文章主要是介绍Oracle常用的命令中如何查看表的结构,如果你对Oracle常用的命令中如何查看表的结构的这一实际操作方案感兴趣的话,你就可以浏览以下的文章对其有一个更好的了解。EDITDATA 表名;修改表字段:Alter table 表名 modify(字段名 类型 约束);alter table test modify (addd varchar2(10) null); alter table 表名 add(字段名 类型 约束);alter table test add(age varchar2(5)); 1.登陆系统用户在Oracle常用命令中查看表结构sqlplus 然后输入系统用户名和密码登陆别的用户conn 用户名/密码;2.创建表空间create tablespace 空间名 datafile 'c:\空间名' size 15M --表空间的存放路径,初始值为15M autoExtend on next 10M --空间的自动增长的值是10M permanent online; --永久使用 3.创建用户create user shi --创建用户名为shi identified by scj --创建密码为scj default tablespace 表空间名 --默认表空间名 temporary tablespace temp --临时表空间为temp profile default --受profile文件的限制 quota unlimited on 表空间名; --在表空间下面建表不受限制 4.创建角色create role 角色名 identified by 密码;5.给角色授权grant create session to 角色名;--给角色授予创建会话的权限grant 角色名 to 用户名; --把角色授予用户6.给用户授予权限grant connect,resource to shi;--给shi用户授予所有权限 Grant dba to shi;-给shi 用户授予DBA权限 grant create table to shi; --给shi用户授予创建表的权限 7.select table_name from user_tables; 察看当前用户下的所有表8.select tablespace_name from user_tablespaces; 察看当前用户下的 表空间9.select username from dba_users;察看所有用户名称命令 必须用sys as sysdba登陆10.创建表create table 表名( id int not null, name varchar2(20) not null )tablespace 表空间名 --所属的表空间 storage ( initial 64K --表的初始值 minextents 1 --最小扩展值 maxextents unlimited --最大扩展值 ); 11.为usrs表添加主键和索引alter table users add constraint pk primary key (ID); 12.为已经创建users表添加外键alter table users add constraint fk_roleid foreign key (roleid) references role(role_id) on delete cascad; --下边写主表的列 on delete casca......余下全文>>