How to modify the size of column in MySQL table?
Answers
Home
Search
Ad
Science, Tech, Math › Computer Science
How to Change a Column Size or Type in MySQL
Use ALTER TABLE and MODIFY commands to change a MySQL column
Share
Man working on a laptop computer
courtneyk/Getty Images
by
Angela Bradley
Updated September 19, 2018
Just because you made a MySQL column one type or size doesn't mean that it has to stay that way. Changing the column type or size in an existing database is simple.
Changing a Database Column Size and Type
You change a column size or type in MySQL using the ALTER TABLE and MODIFY commands together to make the change.
Let's say, for example, that you have a column named "State" on a table named "Address" and you previously set it up to hold two characters, expecting people to use 2-character state abbreviations. You find that several people entered entire names instead of 2-character abbreviations, and you want to allow them to do this. You need to make this column larger to allow the full state names to fit. Here is how you do it:
ALTER TABLE address MODIFY state VARCHAR(20) ;
In generic terms, you use the ALTER TABLE command followed by the table name, then the MODIFY command followed by the column name and new type and size. Here is an example:ALTER TABLE tablename MODIFY columnname VARCHAR(20) ;
The maximum width of the column is determined by the number in parentheses. The type is identified by VARCHAR as being a variable character field.
if you are satisfy with my ans then mark me as a brainlist
if there is something wrong then kindly rectify it