mysql 插入 更新 刪除資料

2022-07-03 06:57:15 字數 1354 閱讀 7630

1.  插入資料

(1)為表所有字段插入資料

insert

into 表名 values(值1,值2....值n);

(2)為指定字段插入資料

insert

into 表名(屬性1,屬性2...屬性m) values(值1,值2...值m);

(3)插入多條記錄

insert

into 表名(屬性列表) values(取值列表1),(取值列表2)....(取值列表n);

(4)將查詢結果插入表中

insert

into 表1(屬性列表1) select 屬性列表2 from 表2 ...

2. 更新資料

update 表名 set 屬性名1=取值1,屬性名2=取值2...屬性名n=取值n where 條件;

3. 刪除資料

delete

from 表名 [

where 條件

];

1. 欄位為datetime型別,插入資料

insert into table1(date1) values( str_to_date('2020-05-01 10:12:15','%y-%m-%d %h:%i:%s') )

mysql日期和字元相互轉換方法

date_format(date,

'%y-%m-%d

') -------------->oracle中的to_char();

str_to_date(date,

'%y-%m-%d

') -------------->oracle中的to_date();

%y:代表4位的年份

%y:代表2為的年份

%m:代表月, 格式為(01……12

)  %c:代表月, 格式為(1……12

)  %d:代表月份中的天數,格式為(00……31

)  %e:代表月份中的天數, 格式為(0……31

)  %h:代表小時,格式為(00……23

)  %k:代表 小時,格式為(0……23

)  %h: 代表小時,格式為(01……12

)  %i: 代表小時,格式為(01……12

)  %l :代表小時,格式為(1……12

)  %i: 代表分鐘, 格式為(00……59

)  %r:代表 時間,格式為12 小時(hh:mm:ss [ap]m)

%t:代表 時間,格式為24 小時(hh:mm:ss)

%s:代表 秒,格式為(00……59

)  %s:代表 秒,格式為(00……59)

MySQL插入更新刪除資料

更新資料 select from person where id 10 update person set age 15,name liming where id 10 select from person where id 10 update person set info student whe...

MySQL 插入 更新 刪除資料

我們吧檢索單獨拉出去,是因為在jdbc中對於檢索的處理,和對於插入,更新,刪除操作是不同的。現在我們將分別介紹mysql的insert插入語句,update更新語句,delete刪除語句。part 1 插入資料 sql語句中,insert是用來插入的 或新增 插入或新增乙個行到資料庫中。有以下幾種方...

MySQL 插入 更新 刪除資料

插入 更新 刪除資料 一 插入資料 插入資料使用 insert 語句向表插入資料記錄,插入資料有四種方式,即為所有字段插入資料 為指定字段輸入資料 同時插入多條資料以及插入查詢結果。先建立乙個表,方便下面舉例 create table student stu id int 10 primary ke...