創建一個和a表一樣的空表----create table newtable as select * from a where 1=2;
創建一個和a表一樣的表-----create table newtable as select * from a;
創建一個表---主鍵約束
CREATETABLE stu(
sid CHAR(6) PRIMARY KEY,
sname VARCHAR(20),
age INT,
gender VARCHAR(10)
);
創建一個表---主鍵自增長
CREATE TABLE stu(
sid INT PRIMARY KEY AUTO_INCREMENT,
sname VARCHAR(20),
age INT,
gender VARCHAR(10)
);
----非空約束
CREATE TABLE stu(
sid INT PRIMARY KEY AUTO_INCREMENT,
sname VARCHAR(10) NOT NULL,
age INT,
gender VARCHAR(10)
);
------------唯一約束 類似主鍵
CREATE TABLE tab_ab(
sidINT PRIMARY KEY AUTO_INCREMENT,
snameVARCHAR(10) UNIQUE
);
------------指定外鍵約束
CREATE TABLE t_section(
sid INTPRIMARY KEY AUTO_INCREMENT,
sname VARCHAR(30),
u_id INT,
CONSTRAINT t_user FOREIGN KEY(u_id) REFERENCES t_user(uid)
);
------授權陳述句
grant connect ,resource to user1; ---授予用戶權限
grant connect, resource to user1 with admin option; //可以傳遞所獲權限。
grant select, update on product to user02 with grant option;
grant create any table,create procedure to role1;
grant role1 to user1;
grant select on table1 to user1;
grant select any table to user1;
給用戶精確賦予權限
GRANT CREATE USER,DROP USER,ALTER USER ,CREATE ANY VIEW ,
DROP ANY VIEW,EXP_FULL_DATABASE,IMP_FULL_DATABASE,
DBA,CONNECT,RESOURCE,CREATE SESSION TO 用戶名字
----- 回收權限
Revoke connect, resource from user50;
Revoke select, update on product from user02;
----插入
insert into newTable select * from oldTable;
insert into Table1(Table1.c1,Table1.c2) select Table2.c1,Table2.c2 from Table2.
查看用戶表空間使用情況
select
b.file_id 檔案ID號,
b.tablespace_name 表空間名,
b.bytes/1024/1024||'M'位元組數,
(b.bytes-sum(nvl(a.bytes,0)))/1024/1024||'M' 已使用,
sum(nvl(a.bytes,0))/1024/1024||'M' 剩余空間,
100 - sum(nvl(a.bytes,0))/(b.bytes)*100 占用百分比
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_id,b.bytes
order by b.file_id;
查看臨時表空間 (dba_temp_files視圖)(v_$tempfile視圖)
select tablespace_name,file_name,bytes/1024/1024 file_size,autoextensible from dba_temp_files;
select status,enabled, name, bytes/1024/1024 file_size from v$tempfile;--sys用戶查看
查看空間地址
select file_name , tablespace_name from dba_data_files;
查看表空間是否為自動增長
select tablespace_name,file_name,autoextensible from dba_data_files where tablespace_name = 'USERS';
將空間設定為自動增長
alter database datafile '/home/oracle/ts01.dbf' autoextend on next 5m maxsize unlimited;
將臨時資料檔案設為自動擴展:
alter database tempfile ‘/u01/app/oracle/oradata/orcl/temp01.dbf’ autoextend on next 5m maxsize unlimited;
增大臨時檔案大小:
alter database tempfile ‘/u01/app/oracle/oradata/orcl/temp01.dbf’ resize 100m;
增加檔案大小
alter database datafile '\oracle\oradata\anita_2008.dbf' resize 4000m。
創建臨時表空間
SQL> create temporary tablespace test1temp
tempfile '/home/u01/app/oracle/oradata/ytzx/test1temp01.dbf'
size 10240m
autoextend on next 1024m
maxsize 20480m
extent management local ;
創建資料表空間
create tablespace test1
logging
datafile '/home/u01/app/oracle/oradata/ytzx/test1.dbf'
size 10240M --50-100G
autoextend on next 2000M
maxsize unlimited
extent management local autoallocate
segment space management auto ;
同一空間新增存盤檔案
ALTER TABLESPACE 表空間名
ADD DATAFILE '資料檔案路徑'
SIZE 500M
AUTOEXTEND
ON NEXT 1M
MAXSIZE UNLIMITED;
為用戶重新指定表空間 (設定為自動增長)
alter user username default tablespace userspace;
**桔妹導讀:**深耕人工智能領域,致力于探索AI讓出行更美好的滴滴AI Labs再次斬獲國際大獎,這次獲獎的專案是什么呢?一起來看看詳細報道吧! 近日,由國際計算語言學協會ACL(The Association for Computational Linguistics)舉辦的世界最具影響力的機器 ......
我們經常在資料庫中使用 LIKE 運算子來完成對資料的模糊搜索,LIKE 運算子用于在 WHERE 子句中搜索列中的指定模式。 如果需要查找客戶表中所有姓氏是“張”的資料,可以使用下面的 SQL 陳述句: SELECT * FROM Customer WHERE Name LIKE '張%' 如果需要 ......
關于MySQL的二進制日志(binlog),我們都知道二進制日志(binlog)非常重要,尤其當你需要point to point災難恢復的時侯,所以我們要對其進行備份。關于二進制日志(binlog)的備份,可以基于flush logs方式先切換binlog,然后拷貝&壓縮到到遠程服務器或本地服務器 ......