2

当我运行附加示例时,它会创建具有列 ID 和数据类型 bigint(295) 的表,我想将其定义为 int(11)。在更复杂的查询中(我有来自组 concat 的 id)我有文本而不是 int。

如何将创建表上的数据类型指定为mysql中的选择?

DROP TABLE IF EXISTS some_table;
CREATE TABLE IF NOT EXISTS some_table AS (
SELECT
CONVERT("123,456,789,987,654,321,741,852,963,147,258,369,123,456,789,987,654,321,741,852,963,147,258,369
  ,2123,456,789,987,654,321,741,852,963,147,258,369,123,456,789,987,654,321,741,852,963,147,258,369
  ,3123,456,789,987,654,321,741,852,963,147,258,369,123,456,789,987,654,321,741,852,963,147,258,369"
, SIGNED INTEGER) AS id);
4

1 回答 1

2

我找不到直接的方法来做到这一点。通过alter table解决它,对我有用,也许有更好的解决方案。

DROP TABLE IF EXISTS some_table;
CREATE TABLE IF NOT EXISTS some_table AS (
SELECT
CONVERT("123,456,789,987,654,321,741,852,963,147,258,369,123,456,789,987,654,321,741,852,963,147,258,369
  ,2123,456,789,987,654,321,741,852,963,147,258,369,123,456,789,987,654,321,741,852,963,147,258,369
  ,3123,456,789,987,654,321,741,852,963,147,258,369,123,456,789,987,654,321,741,852,963,147,258,369"
, SIGNED INTEGER) AS id);

ALTER TABLE some_table CHANGE id id INT( 11 ) NULL DEFAULT NULL ;
于 2012-08-19T11:46:46.970 回答