开发者

How to change the number of characters outputted in mySQL?

开发者 https://www.devze.com 2023-03-12 11:45 出处:网络
I have this mysql query. It generates a table with a 30 character long id. Im wondering wh开发者_StackOverflow社区at I can change to change the 30 character id to a 9 character one.

I have this mysql query. It generates a table with a 30 character long id. Im wondering wh开发者_StackOverflow社区at I can change to change the 30 character id to a 9 character one.

CREATE TABLE IF NOT EXISTS `links` (
  `id` char(30) character set latin1 collate latin1_general_cs NOT NULL,
  `ip` varchar(15) NOT NULL,
  `hit` int(15) NOT NULL default '0',
  `whohit` text,
  `subscribe` tinyint(1) default '0',
  PRIMARY KEY  (`id`),
  KEY `ip` (`ip`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


I guess you need ALTER TABLE command. Go to MySQL console and run this query:

ALTER TABLE links CHANGE `id` `id` char(9) 
    character set latin1 collate latin1_general_cs NOT NULL;

This command will change type of already created column.


I have this mysql query. It generates a table with a 30 character long id. Im wondering what I can change to change the 30 character id to a 9 character one.

Swap...

`id` char(30)

...with...

`id` char(9)

This will create the id column to be be of char type, 9 chars wide.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号