Drop Table Column In MySQL

Drop Table Column In MySQL

Here we show how  you can drop a column from table in MySQL.

Sometime, we not need a particular column of table. So, we delete this column from the table.

Syntax:  

				
					ALTER TABLE table_name DROP COLUMN column_name;
				
			

First we create a sample table with data.

				
					CREATE TABLE `employees` (
  `employee_id` int(11) NOT NULL,
  `employee_name` varchar(100) NOT NULL,
  `salary` int(11) NOT NULL,
  `department` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `employees` (`employee_id`, `employee_name`, `salary`, `department`) VALUES
(1, 'Mohan', 10000, 'Sales'),
(2, 'Manoj', 9000, 'Technology'),
(3, 'Manveer', 8000, 'Marketing'),
(4, 'Manpreet', 7000, 'Human Resources'),
(5, 'Manmohan', 6000, 'Administration'),
(6, 'Ravi', 10000, 'Sales'),
(7, 'Rohan', 9000, 'Technology'),
(8, 'Ravindra', 8000, 'Marketing'),
(9, 'Ranveer', 7000, 'Human Resources'),
(10, 'Rahul', 6000, 'Administration'),
(11, 'pappu', 5000, 'Cleaning');
--
-- Indexes for table `employees`
--
ALTER TABLE `employees`
  ADD PRIMARY KEY (`employee_id`);
--
-- AUTO_INCREMENT for table `employees`
--
ALTER TABLE `employees`
  MODIFY `employee_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12;
COMMIT;

				
			

In the above table we not want department column.

Query:

				
					ALTER TABLE `employees` DROP COLUMN `department`;
				
			

After execute above query.

Table show like below image.

In above image you can see that department column is not present. department column is delete from table .

I hope this article helps you.
Thanks for visiting Inflay.com .