Oracle創(chuàng)建表語(yǔ)句詳解
一、前言
oracle 創(chuàng)建表時(shí),表名稱會(huì)自動(dòng)轉(zhuǎn)換成大寫(xiě),oracle 對(duì)表名稱的大小寫(xiě)不敏感。
oracle 表命名規(guī)則:
- 1、必須以字母開(kāi)頭
- 2、長(zhǎng)度不能超過(guò)30個(gè)字符
- 3、避免使用 Oracle 的關(guān)鍵字
- 4、只能使用A-Z、a-z、0-9、_#S
二、語(yǔ)法
2.1 創(chuàng)建表 create table
-- 創(chuàng)建表: student_info 屬主: scott (默認(rèn)當(dāng)前用戶) create table scott.student_info ( sno number(10) constraint pk_si_sno primary key, sname varchar2(10), sex varchar2(2), create_date date ); -- 添加注釋 comment on table scott.student_info is '學(xué)生信息表'; comment on column scott.student_info.sno is '學(xué)號(hào)'; comment on column scott.student_info.sname is '姓名'; comment on column scott.student_info.sex is '性別'; comment on column scott.student_info.create_date is '創(chuàng)建日期'; -- 語(yǔ)句授權(quán),如:給 hr 用戶下列權(quán)限 grant select, insert, update, delete on scott.student_info to hr;
插入驗(yàn)證數(shù)據(jù):
-- 插入數(shù)據(jù) insert into scott.student_info (sno, sname, sex, create_date) values (1, '張三', '男', sysdate); insert into scott.student_info (sno, sname, sex, create_date) values (2, '李四', '女', sysdate); insert into scott.student_info (sno, sname, sex, create_date) values (3, '王五', '男', sysdate); -- 修改 update scott.student_info si set si.sex = '女' where si.sno = 3; -- 刪除 delete scott.student_info si where si.sno = 1; -- 提交 commit; -- 查詢 select * from scott.student_info;
2.2 修改表 alter table
1. '增加' 一列或者多列
alter table scott.student_info add address varchar2(50); alter table scott.student_info add (id_type varchar2(2), id_no varchar2(10));
2. '修改' 一列或者多列
- (1) 數(shù)據(jù)類型
alter table scott.student_info modify address varchar2(100); alter table scott.student_info modify (id_type varchar(20), id_no varchar2(20));
- (2) 列名
alter table scott.student_info rename column address to new_address;
- (3) 表名
alter table scott.student_info rename to new_student_info ; alter table scott.new_student_info rename to student_info;
3. '刪除' 一列或者多列,刪除多列時(shí),不需要關(guān)鍵字 column
alter table scott.student_info drop column sex; alter table scott.student_info drop (id_type, id_no);
2.3 刪除表 drop table
-- 刪除表結(jié)構(gòu) drop table scott.student_info;
2.4 清空表 truncate table
-- 清空表數(shù)據(jù) truncate table scott.student_info;
2.5 查詢表、列、備注信息
- 權(quán)限從大到小:
'dba_xx' > all_xx > user_xx ('dba_xx' DBA 用戶才有權(quán)限)
- 1. 查詢表信息
select * from dba_tables; -- all_tables、user_tables
- 2. 查詢表的備注信息
select * from dba_tab_comments;
- 3. 查詢列信息
select * from dba_tab_cols t order by t.column_id;
- 4. 查詢列的備注信息
select * from dba_col_comments;
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Oracle數(shù)學(xué)相關(guān)函數(shù)小結(jié)
這篇文章主要介紹了Oracle數(shù)學(xué)相關(guān)函數(shù),實(shí)例總結(jié)了Oracle常用的數(shù)學(xué)相關(guān)函數(shù)并給出了相應(yīng)用法示例,需要的朋友可以參考下2016-03-03Linux環(huán)境下重啟Oracle數(shù)據(jù)庫(kù)詳細(xì)圖文教程
Linux系統(tǒng)下網(wǎng)站出現(xiàn)問(wèn)題的時(shí)候,可通過(guò)重啟oracle數(shù)據(jù)庫(kù)進(jìn)行處理,這篇文章主要給大家介紹了關(guān)于Linux環(huán)境下重啟Oracle數(shù)據(jù)庫(kù)詳細(xì)圖文教程的相關(guān)資料,需要的朋友可以參考下2023-12-12在Oracle關(guān)閉情況下如何修改spfile的參數(shù)
大家都知道在Oracle中pfile參數(shù)是可以手動(dòng)更改的,但是spfile是二進(jìn)制文件所以不可以手動(dòng)更改,但我最近遇到了一個(gè)問(wèn)題,修改參數(shù)錯(cuò)誤,導(dǎo)致Oracle啟動(dòng)不了,一定要修改spfile該怎么辦呢?下面通過(guò)這篇文章來(lái)一起看看吧。2016-12-12Oracle中rank,over partition函數(shù)的使用方法
本文主要介紹Oracle中rank,over partition函數(shù)的用法,希望對(duì)大家有所幫助。2016-05-05Oracle單行子查詢返回多行結(jié)果的問(wèn)題解決
這篇文章主要給大家介紹了關(guān)于Oracle中單行子查詢返回多行結(jié)果的問(wèn)題解決的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用oracle具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2023-07-07window10 安裝Oracle19C 和SQL Developer 的圖文教程
這篇文章主要介紹了window10 安裝Oracle19C 和SQL Developer 教程(圖文詳解),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03