Oracle資料庫基礎--建表語法+操作

来源:https://www.cnblogs.com/yjxt/archive/2018/01/05/8193801.html
-Advertisement-
Play Games

語法 1、建表 create table 表名( 列名 數據類型, …… ); 2、刪除表:drop table 表名; 3、添加列:alter table 表名 add(列名 數據類型); 4、修改列:alter table 表名 rename column 原列名 to 列名; 5、修改數據類型 ...


語法

  1、建表

create table 表名(

  列名 數據類型,

  ……

);

2、刪除表:drop table 表名;

3、添加列:alter table 表名 add(列名 數據類型);

4、修改列:alter table 表名 rename column 原列名 to 列名;

5、修改數據類型:alter table 表名 modify 列名 數據類型;

6、刪除列:alter table 表名 drop column 列名;

7、添加註釋

  添加表註釋:comment on table 表名 is '表註釋;

  添加欄位註釋:comment on column 表名.列名 is '列註釋';

8、添加約束

  添加主鍵約束:alter table 表名 primary key(列名);

  添加唯一約束:alter table 表名 constraint 約束名 unique(列名);

  (主鍵約束和唯一約束的區別:主鍵約束:唯一標識,不能為空。唯一約束:唯一標識,只能有一個值為空

  非空約束:alter table 表名 modify(列名 constraints);

9、插入數據:insert into(列名,……)values(數據,……);

  註意,oracle中不能直接寫入日期函數

  插入時間:to_date('2018-1-4 15:53:34','YYYY-MM-DD HH24:MI:SS')

  插入當前時間:sysdate

 

下麵是我做的一個例子,應用到了上面的語法:

 

 1 --student表
 2 create table student(
 3   stu_id varchar2(10) primary key,
 4   stu_name varchar2(10) not null,
 5   stu_sex varchar2(2) not null,
 6   stu_birthday date,
 7   class_id number
 8 );
 9 --添加表註釋
10 comment on table student is '學生信息表';
11 --欄位添加註釋
12 comment on column student.stu_id is '學號(主鍵)';
13 comment on column student.stu_name is '學生姓名';
14 comment on column student.stu_sex is '學生性別';
15 comment on column student.stu_birthday is '學生出生年月';
16 comment on column student.class_id is '學生所在班級';
17 
18 --sclass表
19 create table sclass(
20   class_id number primary key,
21   class_name varchar2(10) not null
22 );
23 comment on table sclass is '班級信息表';
24 comment on column sclass.class_id is '班級編號';
25 comment on column sclass.class_name is '班級名稱'; 
26 
27 --添加外鍵
28 alter table student add constraint fk_class_id foreign key(class_id) references sclass(class_id);
29 
30 --添加數據
31 insert into sclass(class_id, class_name)values(1,'計應1401');
32 insert into sclass(class_id, class_name)values(2,'計網1401');
33 insert into sclass(class_id, class_name)values(3,'軟體1401');
34 insert into student(stu_id, stu_name, stu_sex, stu_birthday, class_id)values('A001','張珊','',to_date('1995-10-02','yyyy-mm-dd'),1) ;
35 insert into student(stu_id, stu_name, stu_sex, stu_birthday, class_id)values('A002','李思','',to_date('1995-10-02','yyyy-mm-dd'),1) ;
36 insert into student(stu_id, stu_name, stu_sex, stu_birthday, class_id)values('A003','王武','',to_date('1996-10-02','yyyy-mm-dd'),2) ;
37 insert into student(stu_id, stu_name, stu_sex, stu_birthday, class_id)values('A004','趙柳','',to_date('1996-12-02','yyyy-mm-dd'),3) ;
38 insert into student(stu_id, stu_name, stu_sex, stu_birthday, class_id)values('A005','趙柳','',sysdate,3) ;

 



 

 

 

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 操作系統 : CentOS7.3.1611_x64 go語言版本:1.8.3 linux/amd64 InfluxDB版本:1.1.0 源碼路徑: github.com/influxdata/influxdb/cmd/influxd 程式入口(main.go): 在main函數中,調用Main.Ru ...
  • 1. 優先安裝軟體1. net framework3.5。2. 在安裝SQL SERVER 2012前需要3.5的支持。在WIN 2012系統可以在系統管理的添加角色和功能中安裝,如下將【.NET Framework 3.5功能】、【.NET Framework 4.5功能】下的組件全部勾選上。3.... ...
  • Sqoop是一個用來將Hadoop和關係型資料庫中的數據相互轉移的工具,可以將一個關係型資料庫(例如 : MySQL ,Oracle ,Postgres等)中的數據導進到Hadoop的HDFS中,也可以將HDFS的數據導進到關係型資料庫中。Sqoop是為大數據集設計的。Sqoop支持增量更新,將新記 ...
  • SQL Server授權購買簡單介紹 之前有同事問我,使用盜版序列號的SQL Server到底有沒有性能限制,之前本人一直沒有深入研究過,後來經過一番資料搜集和查證,彙總成這篇文章 微軟的SQL Server產品分為兩種賣法 1、盒裝 1、盒裝 :Server+CAL授權方式(SQL2017取消了S ...
  • 概念對比介紹 相信有些人會對ORACLE當中的AMM(Automatic Memory Management)與ASMM(Automatic Shared Memory Management)有些迷惑或混淆,不清楚兩者的異同,本文會從幾個方面來總結一下兩者的異同。如有不足或疏漏之處,敬請指正! 從O... ...
  • Liquibase是一個用於跟蹤、管理和應用資料庫變化的開源的資料庫重構工具。它將所有資料庫的變化(包括結構和數據)都保存在XML文件中,便於版本控制。 Liquibase具備如下特性:* 不依賴於特定的資料庫,目前支持包括Oracle/Sql Server/DB2/MySql/Sybase/Pos ...
  • 通過phpmyadmin登陸時提示以下錯誤: phpmyadmin crypt_random_string requires at least one symmetric cipher be loaded 報錯原因:路徑問題。 解決辦法: 1、進入到phpmyadmin根目錄下,打開\librari ...
  • 學習目標: -多列子查詢 -SQL語句中使用標量子查詢 -更新或刪除行使用關聯子查詢 -使用EXISTS和NOT EXISTS操作符 -使用WITH子句 多列子查詢 語法: Main query WHERE (<column_name>,<column_name>) IN Subquery; 列的比 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...