1. 程式人生 > 其它 >PL/SQL Developer圖形化視窗建立資料庫(表空間和使用者)以及相關查詢sql

PL/SQL Developer圖形化視窗建立資料庫(表空間和使用者)以及相關查詢sql

第一步、先用系統管理員登入pl/sql

  我這裡系統管理員使用者名稱為system,密碼為orcl

第二步、建立表空間

  新建sql視窗,我們使用sql語句來建立表空間

create  tablespace db_test --表空間名
datafile 'D:\oracle\product\11.2.0\dbhome_1\oradata\orcl\test.dbf' --物理檔案 表空間資料檔案存放路徑
size 50m  --大小初始值
autoextend on  --自動擴充套件
next 50m maxsize 20480m  --每次擴充套件50m,最大為20480m
extent management local;

  f8 執行sql,成功後電腦裡會出現TEST.DBF檔案。

第三步、建立使用者

 create user testdev         --建立使用者名稱 testdev
  identified by "test1234"     --建立密碼 test1234
  default tablespace db_test    --表空間  db_test
  temporary tablespace TEMP     --臨時表空間(預設的)
  profile DEFAULT               --預設許可權(下面給分配)
  quota unlimited on db_test;      --
該使用者在 db_test 表空間裡的配額不限

第四步、給使用者分配許可權

grant all privileges to testdev; -- 執行該語句給 testdev 使用者授權,此時 該 使用者就可以登入了

第五步、接下來使用test使用者登入,就可以建表了。

  根據經驗,建表時欄位名儘量要避開使用oracle的關鍵字和保留字。

補充:

  oracle查詢庫中所有表名欄位名、欄位名說明,查詢表的資料條數、表名、中文表名等

    --查詢所有表名:

  select t.table_name from user_tables t;

  --查詢所有欄位名:

  select

t.column_name from user_col_comments t;    

  --查詢指定表的所有欄位名:

  select t.column_name from user_col_comments t where t.table_name = 'BIZ_DICT_XB';

  --查詢指定表的所有欄位名和欄位說明:

  select t.column_name, t.column_name from user_col_comments t where t.table_name = 'BIZ_DICT_XB';

  --查詢所有表的表名和表說明:

  select t.table_name,f.comments from user_tables t inner join user_tab_comments f on t.table_name = f.table_name;

  --查詢模糊表名的表名和表說明:

  select t.table_name from user_tables t where t.table_name like 'BIZ_DICT%';

  select t.table_name,f.comments from user_tables t inner join user_tab_comments f on t.table_name = f.table_name where t.table_name like 'BIZ_DICT%';

  --查詢表的資料條數、表名、中文表名

  select a.num_rows, a.TABLE_NAME, b.COMMENTS

  from user_tables a, user_tab_comments b

  WHERE a.TABLE_NAME = b.TABLE_NAME

  order by TABLE_NAME;

  oracle 查詢表空間的大小及使用情況等sql

--1、查看錶空間的名稱及大小 
SELECT t.tablespace_name, round(SUM(bytes / (1024 * 1024)), 0) ts_size 
FROM dba_tablespaces t, dba_data_files d 
WHERE t.tablespace_name = d.tablespace_name 
GROUP BY t.tablespace_name; 
--2、查看錶空間物理檔案的名稱及大小 
SELECT tablespace_name, 
file_id, 
file_name, 
round(bytes / (1024 * 1024), 0) total_space 
FROM dba_data_files 
ORDER BY tablespace_name; 
--3、查看回滾段名稱及大小 
SELECT segment_name, 
tablespace_name, 
r.status, 
(initial_extent / 1024) initialextent, 
(next_extent / 1024) nextextent, 
max_extents, 
v.curext curextent 
FROM dba_rollback_segs r, v$rollstat v 
WHERE r.segment_id = v.usn(+) 
ORDER BY segment_name; 
--4、檢視控制檔案 
SELECT NAME FROM v$controlfile; 
--5、檢視日誌檔案 
SELECT MEMBER FROM v$logfile; 
--6、查看錶空間的使用情況 
SELECT SUM(bytes) / (1024 * 1024) AS free_space, tablespace_name 
FROM dba_free_space 
GROUP BY tablespace_name; 
SELECT a.tablespace_name, 
a.bytes total, 
b.bytes used, 
c.bytes free, 
(b.bytes * 100) / a.bytes "% USED ", 
(c.bytes * 100) / a.bytes "% FREE " 
FROM sys.sm$ts_avail a, sys.sm$ts_used b, sys.sm$ts_free c 
WHERE a.tablespace_name = b.tablespace_name 
AND a.tablespace_name = c.tablespace_name; 
--7、檢視資料庫庫物件 
SELECT owner, object_type, status, COUNT(*) count# 
FROM all_objects 
GROUP BY owner, object_type, status; 
--8、檢視資料庫的版本  
SELECT version 
FROM product_component_version 
WHERE substr(product, 1, 6) = 'Oracle'; 
--9、檢視資料庫的建立日期和歸檔方式 
SELECT created, log_mode, log_mode FROM v$database; 
--1G=1024MB 
--1M=1024KB 
--1K=1024Bytes 
--1M=11048576Bytes 
--1G=1024*11048576Bytes=11313741824Bytes 
SELECT a.tablespace_name "表空間名", 
total "表空間大小", 
free "表空間剩餘大小", 
(total - free) "表空間使用大小", 
total / (1024 * 1024 * 1024) "表空間大小(G)", 
free / (1024 * 1024 * 1024) "表空間剩餘大小(G)", 
(total - free) / (1024 * 1024 * 1024) "表空間使用大小(G)", 
round((total - free) / total, 4) * 100 "使用率 %" 
FROM (SELECT tablespace_name, SUM(bytes) free 
FROM dba_free_space 
GROUP BY tablespace_name) a, 
(SELECT tablespace_name, SUM(bytes) total 
FROM dba_data_files 
GROUP BY tablespace_name) b 
WHERE a.tablespace_name = b.tablespace_name 
所謂迷茫,就是清醒的看著自己沉淪。 不過總會遇到那束光,或早,或晚。