--:ddl資料庫定義語言
--描述主要的資料庫物件
--建立表
--描述各種資料型別
--修改表的定義
--刪除,重新命名和情況表
--常見的資料庫物件
--表 基本的資料儲存集合有行到列組成
--檢視 從表中抽離出的邏輯上相關的資料集合.
--序列 提供有規律的資料(一般用作主鍵的值)
--索引 提高查詢效率
--同義詞 給物件起別名
--命名規則
--表名和列名
--必須以字母開頭
--必須在1-30個字元以內
--只由a-z,a-z,0-9,_,$和#組成
--必須不能是oracle的保留字
--必須不能和使用者定義的其他物件重名
--建立表的方式
--第一種方式(白手起家式)
--第二種方式(依託於某個已經存在的表)
create table emp_1807 as select id,name,age from t_emp where age = 12;
create table emp_1807_1 as select id,name,age,pay from t_emp;
select * from emp_1807_1;
select * from t_emp;
--修改表的定義
--使用alter table 語句
--1.追加新的列
alter table t_emp add(salary number(10));
update t_emp set salary = 1000 where age = 12;
--如果要修改列的屬性,那麼該列必須為空
alter table t_emp modify(salary varchar2(10) default 2000);
--刪除乙個列
alter table t_emp drop column salary;
--資料定義語言是自動提交的
--重新命名表的乙個列名
alter table t_emp rename column age to ages
--刪除表
drop table t_emp;
--清空表資料
delete t_emp;
truncate table t_emp;
rollback;
--資料庫定義語言: 回滾語句無效,相當於會自動提交
--ps:truncate:從硬碟上刪除表中所有資料,釋放硬碟資源
--資料處理語言 dml
--delete:清空表資料 可回滾
--約束
--什麼叫約束:約束是表級的強制規定
--主要的約束有以下5種
--not null 非空約束
--unique 唯一約束
--primary key 主鍵約束
--foreign key
--check
--ps:如果不指定約束名,那麼oracle_server自動按
--sys_cn的格式指定約束名
--建立和修改約束
--建表的同時
--建表之後
--可以在表級或列級定義約束
--ps:可以通過資料字典檢視檢視約束
--表級約束和列級約束
--作用範圍
--1.列級約束只能作用在乙個列上
--2.表級約束可以作用在多個列上(當然表級約束也可以作用在乙個列上)
--定義方式
--1.列級約束必須跟在列的定義,表約束不與列一起,而是單獨定義
--ps:not null:該約束只能定義在列上
create table emp_sc_18(
id number(3) constraint emp_sc_01_id_nn not null,
name varchar2(20) not null,
salary number(10,2)
)create table emp_3(
id number(3) ,
name varchar2(20) not null,
salary number(10,2),
--表級約束
constraint emp_3 unique(id,name)
)insert into emp_3 values(1,null,1000.0);
--表級約束無法在建表後新增
--如果要新增,只能通過列級的方式
--ps:唯一約束對空值無效
--ps:主鍵的約束是非空且唯一
--外來鍵
ORACLE 資料庫操作語言
建立表空間 create tablespace tbs liuya datafile e orcl.ora size 100m autoextend on 表明表空間不自動擴充套件 調整表空間大小 alter database datafile e orcl.ora resize 200m 改變表空...
Oracle資料庫之DML(資料庫管理語言)
插入資料 insert into 更新資料 update set 更新一豎列 update userinfo set m 更新指定列 update userinfo set m where userinfoid 0003 update userinfo set m where nickname li...
Oracle資料庫 DML 資料操縱語言
資料操縱語言 用於查詢與修改資料記錄 其中包括 insert 插入資料 update 修改資料 delete 刪除資料。insert 插入資料 把資料插入到資料庫中指定的位置,insert語法一次只能向表中插入一條資料。語法格式 使用規則 為每一列新增乙個新值,可以是指定值或空值。按列的預設順序列出...