注意Mysql資料截斷

2021-05-21 21:11:43 字數 1466 閱讀 1511

比如:有乙個表aritcle和另乙個表article_comment,關聯是article的id

create table `article` (

`id` int(10) unsigned not null auto_increment,

`name` varchar(200) not null,

primary key (`id`)

) engine=innodb;

create table `article_comment` (

`id` int(10) unsigned not null auto_increment,

`text` varchar(200) not null,

`article_id` int(10) unsigned not null,

primary key (`id`),

key `art_id` (`article_id`),

constraint `art_id` foreign key (`article_id`) references `article` (`id`) on delete cascade on update cascade

) engine=innodb;

set sql_mode='';

insert into article values(12345678901,'name1');

insert into article_comment(text,article_id) values('text1',12345678901);

insert into article_comment(text,article_id) values('text2',12345678902);

檢視資料:

article表

4294967295 name1

article_comment表

show warnings顯示

warning | 1265 | data truncated for column 'article_id' at row 1

這會造成:

怎樣解決呢?

';insert into article_comment(text,article_id) values('text1',12345678903);

這會報錯:

[sql] insert into article_comment(text,article_id) values('text1',12345678903);

[err] 1264 - out of range value for column 'article_id' at row 1

因此也就避免了上述問題。

MySql截斷表 清空表資料

truncate table users 截斷表可以用於刪除表中的所有資料。截斷表命令還會 所有索引的分配頁。截斷表的執行速度與不帶where子句的delete 刪除 命令相同,甚至比它還要快。delete 刪除 一次刪除一行資料,並且將每一行被刪除的資料都作為乙個事務記錄日誌 而truncate ...

nginx 返回資料被截斷

今天在工作中遇到這麼乙個問題 客戶端向後台請求資料時,如果遇到返回資料很大時,客戶端獲得的資料會被截斷,找了很多地方,最終發現是nginx配置的問題,寫在此如果大家遇到類似問題可以進行參考。當nginx 遇到大資料流時,會把資料存到本地然後分次向客戶端傳輸。於是 1.存入檔案有許可權,讀取檔案沒有許...

資料的擴充套件與截斷

最近時間比較閒,無事拿著深入理解計算機原理讀了起來 突然發現,平時只知道寫 很多細節方面的知識都被我們忽略了,而這些東西隨時都可能給我們的程式造成乙個災難性但卻又難以發現的漏洞,比如在我們平時用c或c 程式設計的時候,我們經常會用到類似資料型別強制轉換等操作,而我們卻沒有用心去考慮,這樣的轉換是否存...