MySQL 資料庫管理系統 七) 插入資料

2021-09-24 22:10:36 字數 2263 閱讀 4712

一、插入資料

1.插入一行

insert into 表名(列名1,列名2,列名3)values(值1,值2,值3);

insert

into orders (order_num,order_date,cust_id)

values

('20010'

,'2005-10-09 00:00:00'

,'10001'

);

2.插入多行資料

insert

into orders (

order_num,

order_date,

cust_id

)values

('20011'

,'2005-10-09 00:00:00'

,'10001'),

('20012'

,'2005-10-10 00:00:00'

,'10002'

);

二、更新和刪除資料

1.更新表

update 表名 set 列名=『』where 搜尋條件

update orders set order_date=

'2015-10-10 00:00:00'

,cust_id=

10003

where order_num=

20012

;

2.刪除資料

delete from 表名 where 條件

delete

from orders where order_num=

20012

;

3.truncate table

刪除原來的表並重新建立乙個表

truncate

table students;

三 建立和操縱表

1.建立表

create

table students

( student_id int

notnull

auto_increment

, student_name char(50

)not

null

default1,

student_city char(50

)not

null

, student_email char(50

)not

null

,primary

key(student_id)

)engine

=innodb

;

2.更新表

給表新增乙個列

alter

table student add student_phone char(20

);

刪除剛新增的主建

alter

table student drop

column student_phone;

3.使用alter table 定義主建

alter

table student add

constraint fk_student_students foreign

key(student_id)

references students (student_id)

;

4.刪除表

drop

table students;

刪除表因為設定了外來鍵 ,不能刪除表

解決辦法:

set foreign_key_checks =0;

// 先設定外來鍵約束檢查關閉

drop

table students;

// 刪除表,如果要刪除檢視,也是如此

set foreign_key_checks =1;

// 開啟外來鍵約束檢查,以保持表結構完整性

show variables like

"foreign%"

;//最後檢查:外來鍵約束是否開啟

5.重命表名

rename

table student to student_11;

MYSQL資料庫管理系統

學習框架 什麼是mysql?mysql的優點 學習mysql需要掌握什麼?定義 最流行的關係型資料庫管理系統,在 web 應用方面 mysql 是最好的rdbms relational database management system 應用軟體之一。mysql是乙個軟體 什麼是rdbms?定義 ...

MySQL資料庫管理系統概述

mysql是最流行的開放原始碼sql資料庫管理系統,它是由mysql ab公司開發 發布並支援的。mysql ab是由多名mysql開發人創辦的一家商業公司。它是一家第二代開放原始碼公司,結合了開放原始碼價值取向 方法和成功的商業模型。1 mysql是一種資料庫管理系統。資料庫是資料的結構化集合。它...

飯卡管理系統mysql 資料庫飯卡管理系統 doc

資料庫飯卡管理系統 數 據 庫 課 程 設 計 題 目 飯卡管理系統 姓 名 學 號 專 業 08計科一班 指導老師 信 息 工 程 學 院 計算機 系 目錄第一章 概述 3 需求分析 4 資料庫設計 5 概念結構設計 5 邏輯結構設計 6 物理結構設計 6 表的建立 8 關係圖 觸發器 7 系統程...