標籤:數字 rom 資料類型 自增 for 方法 off 一個 efault
bigint
從 -2^63 (-9223372036854775808) 到 2^63-1 (9223372036854775807) 的整型資料(所有數字)。儲存大小為 8 個位元組。
int
從 -2^31 (-2,147,483,648) 到 2^31 - 1 (2,147,483,647) 的整型資料(所有數字)。儲存大小為 4 個位元組。int 的 SQL-92 同義字為 integer。
smallint
從 -2^15 (-32,768) 到 2^15 - 1 (32,767) 的整型資料。儲存大小為 2 個位元組。
tinyint
從 0 到 255 的整型資料。儲存大小為 1 位元組。
有時MySQL建立表時儲存設計過小,可以通過以下等方法查看修改:
1。 建立表的時候定義:
create table test ( id int primary key auto_increment)
2. 建立表的時候指定auto_increment的起始值
create table test(id int primary key auto_incrment) auto_increment = 100;
start with 100.... default is 1;
3.去掉自增屬性後,其預設值將變為0
alter table test modify column id int;
4.為欄位添加auto_increment屬性
alter table test modify column id int auto_increment;
5. 修改欄位的初始值
alert table test auto_increment = 200;
6. 怎樣查看一個表的auto_increment的下一個自增ID值
我們知道getLastInsertID()屬性只是擷取插入記錄之後的最大ID,並不是我們想要的,所以我們採用
show table status like ‘tablename‘, 裡麵包含Auto_increment的欄位
第二:
use information_schema;
select Auto_increment from tables where table_name = ‘table_name‘;
其中information_schema一般使用者無法訪問.
7. 修改全域自增參數:
利用 show variables like ‘AUTO_INCREMENT% ‘;
我們將看到
auto_increment_increment, auto_increment_offset, 它們代表全域的起始值和步進,通過如下方式修改:
set auto_increment_increment = 100;
set auto_increment_offset = 10 ;
這將對全域的auto_increment列產生影響,建議慎用!
mysql的資料類型int、bigint、smallint 和 tinyint及id 類型變換