mysql - if 和 col_length 语法

标签 mysql

声明:

if col_length('memes', 'rating_test') is null 
    begin 
    alter table `memes` add column `rating_test` varchar(36) 
    end  

错误消息:

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 'if col_length('memes', 'rating_test') is null begin alter table `memes` add colu' at line 1

为什么会产生上述错误消息?

最佳答案

你的语法不正确,使用这个语法它应该可以工作。

    If Exists (Select 1 from INFORMATION_SCHEMA.TABLES Where  Table_Name = N'YourTableName')
BEGIN
    If(COL_LENGTH('[TableName]','ColumnName') is NULL)
    BEGIN
        Alter Table [TableName]
        Add ColumnName DataType(Size) NULL
    END
END
GO

关于mysql - if 和 col_length 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41529927/

相关文章:

php - 如果值为 true,则为每个项目添加类

mysql查询使用2个表更新表中的数据

mysql - 事件在 mysql 中不能正常工作?

php - 使用php远程连接到mysql服务器

MySQL 5.5 意外 "End_of_input"

php - 如何阻止在 MySQL 中插入空字符串

mysql - 计数器列增量一致吗?

mysql - 从多个表名中选择 *

mysql - JRuby on Rails 和 Solr 索引

mysql - 如何为所有浏览器存储无限量的 cookie 条目