欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Oracle創(chuàng)建表語(yǔ)句詳解

 更新時(shí)間:2024年07月03日 10:51:56   作者:何以解憂,唯有..  
這篇文章主要介紹了Oracle創(chuàng)建表語(yǔ)句,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

一、前言

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)文章

最新評(píng)論