oracle資料表空間基本命令,修改資料表結構基本命令,oracle資料

來源:互聯網
上載者:User

oracle資料表空間基本命令,修改資料表結構基本命令,oracle資料

資料表空間基本命令

--建立資料表空間   初始化大小10M  自動成長5M  最大50M

create tablespace duan datafile 'F:\oracle\product\10.2.0\oradata\orcl\duan.dbf' size 10M 
autoextend 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;










oracle什表的資料需要用alter命令更改?

alter命令是用來改表結構 不是改資料的。屬於DDL資料定義語言 (Data Definition Language)
 
Oracle常用的命令怎查看錶的結構

以下的文章主要是介紹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......餘下全文>>
 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.