質問

How do you update a MySql database bigint field?

Currently our database has a bigint(196605) field which is generating errors. I am pretty sure the field limit is 250 i.e. bigint(250) which explains the errors being generated.

The field itself only stores integer values 3 digits e.g. 100, so I am not sure why it is even bigint. In any case, I need to fix the field without any loss of data.

Any help would be most appreciated!

役に立ちましたか?

解決

This is a common confusion ... BIGINT type has a fixed size is stored on 8B so the ONLY difference between BIGINT(1) and BIGINT(20) is the number of digits that is gonna be displayed 1 digit respectively 20 digits .

If you store only 3 digits numbers ,and you do not think you will need more you can use a SMALLINT UNSIGNED type which takes only 2B instead of 8B so you will save a lot of space and the performance will increase.

I suggest you read this first.

他のヒント

May be when creating database field, you set its length, if we do not set any length then I think it takes 11 as default. but If we pass then it will take specified value as length.

Before you do something, export (backup) your data into an SQL file (autogenerated inserts for your data) to save your data before you change your table and you know that if your data is lost, you can import it.

If you want to change your column, you must update your table like this:

ALTER TABLE tableName CHANGE columnName newColumnName BIGINT(250);

I think this should work.

DIDN'T TESTED (I use MS SQL Server 2008 and can't check if it works)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top