標籤:order by 資料 自動 圖靈 ext student select 表名 rom
Oracle資料庫-常用操作指令
查看連接埠號碼指令
netstat –a
清屏:
SQL> clear scre;SQL> host cls;
資料表空間
建立資料表空間
SQL> create tablespace tc20 datafile ‘e:\tc20_data_dbf‘ size 20m autoextend on next 5m maxsize 500m;
查詢資料表空間名稱
SQL> select tablespace_name,file_name from dba_data_files order by file_name;
查詢所有資料表空間的名稱,和物理檔案名稱。從資料字典(dba_data_files)中查詢。並把查詢的結果進行排序。按照檔案名稱來排(預設升序。)
查詢預設資料表空間
SQL> select user_id,username,default_tablespace from dba_users order by user_id;
每個使用者在登陸資料庫後如果執行建表操作,且沒有顯式的指明該表位於那個資料表空間中,那麼會自動的建立於使用者的預設資料表空間中。這個預設資料表空間相當於使用者的工作空間。這個空間我們可以通過一條語句來查詢。
修改預設資料表空間
SQL> alter database default tablespace TABLE_NAME;
需要注意的是。如果某個資料表空間已經不再使用要被刪除,但是它是預設資料表空間,那麼在刪除之前要解除預設。
對錶空間進行重新命名
SQL> alter tablespace OLD_NAME rename to NEW_NAME;
刪除資料表空間
drop tablespace 名字
這樣刪除是沒有清除內容和刪除本地檔案。如果想一起刪除需要使用
drop tablespace tc20 including contents and datafiles;
表
建立表:
create table 表名 (列1 資料類型,列2 資料類型,...列n 資料類型)tablespace 資料表空間。
SQL> create table student( 2 id number, 3 name varchar2(20), 4 gender number)tablespace MYWORK;
向表中加入資料
SQL> insert into student values (20001,‘圖靈‘,24);
查詢使用者所建立的資料表
SQL> select table_name,tablespace_name from user_tables where lower(table_name)= ‘student‘;
查看已有表的資料結構。
使用select是無法得到具體的建表語句的。想要得到建表語句只有通過下面語句
SQL> describe dual;
比如在插入資料時突然忘記了列的資料類型,就可以通過該語句來查看。
增加新列
SQL> alter table student add(phoneNumber number);
修改列的資料類型
SQL> alter table student modify(age varchar2(15));
刪除已有列
alter table student drop column phonenumber;
刪除使用drop 需要注意的是,在使用刪除列時要配套column使用。因為只有使用了column才可以表明要刪除的是一列。
對列重新命名
SQL> alter table student rename column id to ids;
要注意的是同刪除一樣要加column。表明要改的是一個列的名字。
更改資料表空間
SQL> alter table student move tablespace USERS;
刪除整張表
SQL> drop table student;
表中增加資料:
INSERT INTO students(mid,name,age) VALUES(1,‘張三‘,30);INSERT INTO students(mid,name,age) VALUES(2,‘李四‘,300);
單表查詢:
select命令的文法格式:
select 列1,列2,...,列n from 表 where 條件order by (desc);
Oracle中使用分組有一個注意點: group by的條件必須要在select的列表中出現.或者複合函數中. 即分組兩種寫法:
1.select 列(A) from 表 group by 列(B)
這裡的A和B必須是同一列
2.select 列(A),函數(列B) from 表 group by 列(C)
這裡A和C必須是同以列.A和B不需要一樣.
Oracle資料表空間和表的入門操作指令