mysql的資料類型int、bigint、smallint 和 tinyint及id 類型變換

來源:互聯網
上載者:User

標籤:數字   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 類型變換

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.