如何向MYSQL表添加新列? [英] How to add new column to MYSQL table?

查看:40
本文介绍了如何向MYSQL表添加新列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PHP 向我的 MYSQL 表中添加一个新列.我不确定如何更改我的表以创建新列.在我的评估表中,我有:

I am trying to add a new column to my MYSQL table using PHP. I am unsure how to alter my table so that the new column is created. In my assessment table I have:

assessmentid | q1 | q2 | q3 | q4 | q5 

假设我有一个带有文本框的页面,我在文本框中输入 q6 并按下一个按钮,然后表格将更新为:

Say I have a page with a textbox and I type q6 in to the textbox and press a button then the table is updated to:

assessmentid | q1 | q2 | q3 | q4 | q5 | q6

我的代码:

<?php 
  mysql_query("ALTER TABLE `assessment` ADD newq INT(1) NOT NULL AFTER `q10`");
?>
  <form method="post" action="">
    <input type="text" name="newq" size="20">
    <input type="submit" name="submit" value="Submit">

推荐答案

你的桌子:

q1 | q2 | q3 | q4 | q5

你也可以

ALTER TABLE yourtable ADD q6 VARCHAR( 255 ) after q5

这篇关于如何向MYSQL表添加新列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆