How to ADD Column In MySQL Existing Table Example

How to ADD Column In MySQL Existing Table Example

Open your MySQL Query Editor then copy & paste the below code to make a table "users"

Then copy & paste the below code to add a column in a MySQL Existing table "users"

----------- making a table users ----
----
CREATE TABLE users(
id INT UNSIGNED AUTO_INCREMENT NOT NULL,
username VARCHAR(255) NOT NULL,
password CHAR(40) NOT NULL,
PRIMARY KEY(`id`)
);
----
---
-- ADD Column In MySQL Existing Table
--
-- Lets have a look into an existing table "users"
--
desc users;
--
-- Now adding a new column "active" into the table "users"
--
ALTER TABLE users ADD COLUMN active TINYINT UNSIGNED NOT NULL default 1;
--
--
-- Finally Lets have a look into the table "users" again to get the added column
--
desc users;
--
      -- is comment in MySQL
      -- in fact it is comment in MSSQL and Oracle as well
   

How to ADD Column In MySQL Existing Table Example - Result in MySQL Query Editor

 

Related Tutorial Examples

  1. MySQL sample database script: Create Database using SQL Statement Example
  2. MySQL Sub-Query: INSERT INTO SELECT... Example
  3. MySQL Sub-Query: INSERT INTO SELECT *... Example
  4. MySQL Sub-Query: CREATE TABLE SELECT... Example
  5. MySQL Sub-Query: CREATE TABLE SELECT *... Example
  6. MySQL IF() Function Boolean Value Example
  7. MySQL strcmp() Function Number Value Example
  8. MySQL Stored Procedure Function: How to Drop a Stored Procedure Example
  9. MySQL Stored Procedure Function: Making hello world Function using aliase Example
  10. 20 steps to make CakePHP Blog Project

No comments:

Post a Comment

leave your comments here..