在mysql中创建表以生成自动序列号时出错

时间:2015-04-10 06:57:52

标签: mysql sql-server create-table

我只想在表格中创建序列号,而不仅仅是为了查看例如:

表ConfirmationNumber:


SerialNo

--------------

00000001

00000002

00000003

等等(每次执行查询时序列号都会增加。)

当我在sql中创建一个表时:

CREATE TABLE confirm

(

ConfirmationID int,

name varchar(10),

SequenceNumber AS RIGHT('0000000' + convert(varchar, ConfirmationID), 8)

)

它发出错误:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use near 'AS 
RIGHT('0000000' + convert(int, ConfirmationID), 8)
)' at line 9

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

从标签中删除sql-server。

将所需的代码放在INSERT语句中,或使用TRIGGER。

您还可以使用ZEROFILL属性自动显示0。