Altering MySQL Table to Add New Column
Adding a new column to an existing MySQL table is a straightforward process. In your case, where you want to add a new column named 'q6' to your 'assessment' table, the syntax you can use is:
ALTER TABLE `assessment` ADD `q6` INT(1) NOT NULL AFTER `q10`;
This code will create a new column 'q6' of type Integer (INT) with a size of 1 and set it to not allow null values. The AFTER q10 clause specifies that the new column should be added after the existing 'q10' column.
Your PHP code, however, appears to have a mistake in the column name. You mention adding 'q6' in the question but use 'newq' in the code. Make sure to correct this to match the desired column name.
mysql_query("ALTER TABLE `assessment` ADD `q6` INT(1) NOT NULL AFTER `q10`");
Additionally, you can also specify the data type of the new column directly in the query, as shown below:
ALTER TABLE `assessment` ADD `q6` VARCHAR(255) AFTER `q5`;
This code will create a new column 'q6' of type String (VARCHAR) with a maximum length of 255 characters.
The above is the detailed content of How to add a new column named 'q6' to your 'assessment' table in MySQL?. For more information, please follow other related articles on the PHP Chinese website!