【Oracle】表的管理

來源:互聯網
上載者:User

表名和列的命名和規範

1、必須以字母開頭
2、長度不能超過30字元
3、不能使用Oracle的保留字
4、只能使用A-Z,a-z,0-9,¥,#等

資料類型

字元型:
char 定長 最大2000字元  查詢速度快。
varchar2(20) 變長 最大4000字元
clob(character large object) 字元型大對象 最大4G

數字型:
number 範圍-10的38次方到10的38次方,既可以是整數也可以是小數
number(5,2) 表示一個小數有五位有效數字,2位小數
number(5) 表示一個五位整數

日期類型:
date 包含年月日時分秒
timestamp 時間戳記

圖片:
blob 位元據,可以存放圖片/聲音 4G

建立表:
SQL> create table student(
  2  xh number(4),--學號
  3  xm varchar2(20),--姓名
  4  sex char(2),--性別
  5  birthday date,--生日
  6  sal number(7,2)--獎學金金額
  7  );

添加一個欄位:
alter table student add(classId number(2));

修改欄位的長度:
alter table student modify (xm varchar2(30));

修改欄位的類型/或是名字(不能有資料):
alter table student modify (xm char(30));

刪除一個欄位:
alter table student drop column sal;

修改表的名字:
rename student to stu;

刪除表:
drop table student;

插入資料:
insert into student values(1,'小明','男','20-10月-88','25000.25',12);
into必須有

日期:日-月-年

alter session set nls_date_format='yyyy-mm-dd';

插入部分欄位:
插入空值:null
select * from student where birthday is null;

刪除資料:
delete from student;寫日誌、可恢複、速度慢。
truncate table student;刪除表中所有記錄,表結構還在,不寫日誌,無法找回刪除的記錄,速度快。

savepoint a;//savepoint b;預設覆蓋a
rollback to a;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.