MySQL 03 DML 新增,更新,刪除

2021-10-10 07:04:11 字數 1114 閱讀 7997

dml語言:資料操作語言

用於運算元據庫物件中所包含的資料

包括 :

-- 如果沒有not null或者主鍵約束,則可以任意選擇新增的列

insert

into student(name)

values

('張三');

-- 如果主鍵自增,那能否省略呢?

insert

into student values

('張三');

-- 查詢:insert into student values ('張三');錯誤**:1136

column count doesn`t match

value count at row

1-- 結論:'欄位1,欄位2...'該部分可省略 , 但新增的值務必與表結構,資料列,順序相對應,且數量一致.

-- 一次插入多條資料

insert

into student(name)

values

('王五'),

('趙六'

);

update (更新資料語句)

update 表名 set column_name=

value

[,column_name2=value2,..

.][where condition]

;

注意 :

-- 將id=1的學生姓名改為李四

update student set name =

'李四'

where id =

1;

delete (刪除資料語句)

delete

from 表名 [

where condition]

;

注意:condition為篩選條件 , 如不指定則刪除該錶的所有列資料

-- 刪除id=5的學生資訊

delete

from student where id =

5

c 更新mysql資料 MySQL插入更新刪除資料

資料插入 插入完整的行 insert into customers values null,pep e.lapew 100 main street los angeles ca 90046 usa null null 此例子插入乙個新客戶到customers表。儲存到每個表列中的資料在values子...

MYSQL新增約束,刪除約束新增列,修改列,刪除列

mysql新增約束,刪除約束 新增列,修改列,刪除列 新增主鍵約束 alter table 表名 add constraint 主鍵 形如 pk 表名 primary key 表名 主鍵字段 新增外來鍵約束 alter table 從表 add constraint 外來鍵 形如 fk 從表 主表 ...

mysql存在更新不存在新增

1 插入一條資料,存在則不操作,不存在就插入 必須現有唯一鍵 使用insert ignore語句 insert ignore into table col1,col2 values a b 例如插入資料 insert ignore into user info last name,first nam...