Oracle以dba身份登陸 sqlplus / as sysdba; 1 --查詢創建的序列信息 2 select * from user_sequences; 3 4 --查詢序列的當前值 5 select SQ_TEACHER_TNO.CURRVAL from dual; 6 7 --查詢序列 ...
Oracle以dba身份登陸
sqlplus / as sysdba;
表空間操作
--創建表
create table teacher
(
tNo number(4) not null,
tName varchar2(20) not null,
birthday date
);
--查詢當前用戶下麵所有的表
select * from tab;
--查詢表中的數據
select * from teacher;
--01.給表中新增兩個欄位
alter table teacher add(sal number(7,2),wechat varchar2(20));
--02.修改欄位的屬性
alter table teacher modify(tName varchar2(10));
--03.刪除一個欄位
alter table teacher drop column wechat;
--04.新增主鍵
alter table teacher add constraint pk_teacher_tno primary key(tno);
--05.添加唯一約束
alter table teacher add constraint uk_teacher_tname unique(tname);
--06.增加一個性別欄位
alter table teacher add(sax char(2));
--07.修改欄位的名稱
alter table teacher rename column sax to sex;
--08.增加sex欄位的檢查約束
alter table teacher add constraint ck_teacher_sex check(sex in('男','女'));
--09.刪除檢查約束
alter table teacher drop constraint ck_teacher_sex;
--10.創建外鍵約束 在student 從表中創建
create table student
(
sNo number(4) not null primary key,
tNum number(4) not null
)
alter table student add constraint fk_teacher_student foreign key(tNum)
references teacher(tNo);
![](http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 --查詢創建的序列信息 2 select * from user_sequences; 3 4 --查詢序列的當前值 5 select SQ_TEACHER_TNO.CURRVAL from dual; 6 7 --查詢序列的下個值 8 select SQ_TEACHER_TNO.NEXTVAL from dual; 9 10 --使用序列新增數據 11 insert into teacher(tno,tname) 12 values(SQ_TEACHER_TNO.NEXTVAL,'小黑'); 13 14 --dual是一個Oracle自帶的啞表,只有一個欄位 15 select * from dual; 16 17 --可作計算 18 select 66*66 from dual; 19 --查詢系統時間 20 select sysdate from dual; 21 --以某種格式顯示時間 22 select to_char(sysdate,'yyyy-MM-dd hh:mm:ss') from dual; 23 24 --查詢的結果不存在任何一個表中序列和啞表