douluolan9101 2015-11-23 07:17
浏览 91
已采纳

MySQL使用默认值添加列,使用QUOTES语法

I am doing well with mySql, but when it comes to some quirks I am struck.

This is something I used for years successfully

$sql = "ALTER TABLE " . $Tablu . " ADD " . $Colu . " varchar(" . intVal($Siza) .")";

What I want now is just add a DEFAULT value for the new column I am adding. Please provide a syntax WITH THE EXISTING STRUCTURE of the query. That is with THE QUOTES

I am trying this

$sql = "ALTER TABLE " . $Tablu . " ADD " . $Colu . " varchar(" . intVal($Siza) .") DEFAULT ('" . $defa . "')";

But it is NOT working

I CANNOT understand the without-quotes-mysql game at all.

Thanks in advance

  • 写回答

3条回答 默认 最新

  • doubi1928 2015-11-23 07:28
    关注

    you query is ok .. you just need to remove those brackets () around $defa.. like this-

    $sql = "ALTER TABLE " . $Tablu . " ADD " . $Colu . " varchar(" . intVal($Siza) .") DEFAULT '" . $defa . "'";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?
  • ¥15 (SQL语句|查询结果翻了4倍)
  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用
  • ¥15 用verilog实现tanh函数和softplus函数