MySQL Drop Column In Hindi | MySQL Drop Multiple Columns

📔 : MySQL 🔗

कई बार table schema prepare होने के बाद, आप table से एक या अधिक columns को हटाना चाहते हैं। ऐसे में, आप DROP COLUMN Syntax का use करके columns को remove हैं।

MySQL Drop Column

ALTER TABLE table_name DROP COLUMN column_name;
  • Syntax के according सबसे पहले आपको , उस table का name देना है जिसमे से column को remove करना है।

  • फिर column_name को drop किये जाने वाले column से replace कर दीजिये।

हालाँकि DROP COLUMN Syntax में COLUMN keyword optional है , इसे आप नहीं लिखेंगे तब भी कोई problem नहीं है।

ALTER TABLE table_name DROP column_name;

MySQL Drop Column Example

तो सबसे पहले हम देख लेते हैं कि हमारे current database tutorials में students table में कौन कौन से columns है।

DESCRIBE students;

Output :

+-------------+--------------+------+-----+---------------------+----------------+
| Field       | Type         | Null | Key | Default             | Extra          |
+-------------+--------------+------+-----+---------------------+----------------+
| id          | int(11)      | NO   | PRI | NULL                | auto_increment |
| email       | varchar(100) | YES  |     | NULL                |                |
| full_name   | varchar(100) | YES  |     | NULL                |                |
| address     | varchar(500) | NO   |     | NULL                |                |
| create_date | timestamp    | NO   |     | current_timestamp() |                |
+-------------+--------------+------+-----+---------------------+----------------+
5 rows in set (0.085 sec)

तो जैसा कि आप Output में देख सकते हैं , कि students table में 5 columns हैं हम इसमें से create_date column को drop करेंगे।

ALTER TABLE students DROP create_date;

Output

Query OK, 0 rows affected (0.030 sec)
Records: 0  Duplicates: 0  Warnings: 0

query Ok , होने का मतलब है कि table से column delete हो गया है।

MySQL Drop Multiple Columns

किसी Table से आप Multiple Columns भी delete कर सकते हैं , बस आपको comma separated सभी columns को लिखना होगा। इसके लिए नीचे दिए गए syntax को follow कर सकते हैं।

ALTER TABLE table_name DROP COLUMN column_name_1, DROP COLUMN column_name_2, ...;

Multiple columns को drop करते समय भी DROP COLUMN में COLUMN keyword optional है।

MySQL Drop Multiple Columns Example

ALTER TABLE students DROP address, DROP email;

अब अगर आप students table का structure देखेंगे तो पाएंगे कि 3 columns remove हो चुकें हैं।

DESCRIBE students;

Output

+-----------+--------------+------+-----+---------+----------------+
| Field     | Type         | Null | Key | Default | Extra          |
+-----------+--------------+------+-----+---------+----------------+
| id        | int(11)      | NO   | PRI | NULL    | auto_increment |
| full_name | varchar(100) | YES  |     | NULL    |                |
+-----------+--------------+------+-----+---------+----------------+
2 rows in set (0.058 sec)

आपको MySQL में किसी table से column drop करना समझ आ गया होगा।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers