प्राइमरी की ड्रॉप करने के लिए, पहले ALTER का उपयोग करके टेबल को बदलें। इसके साथ, नीचे दिखाए अनुसार की ड्रॉप करने के लिए DROP का उपयोग करें:
सिंटैक्स
alter table yourTableName drop primary key;
आइए पहले एक टेबल बनाते हैं:
mysql> create table DemoTable -> ( -> StudentId int NOT NULL, -> StudentName varchar(20), -> StudentAge int, -> primary key(StudentId) -> ); Query OK, 0 rows affected (0.48 sec)
टेबल का विवरण जांचने का क्वेरी यहाँ है:
mysql> desc DemoTable;
इससे निम्न आउटपुट प्राप्त होगा:
+-------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+-------+ | StudentId | int(11) | NO | PRI | NULL | | | StudentName | varchar(20) | YES | | NULL | | | StudentAge | int(11) | YES | | NULL | | +-------------+-------------+------+-----+---------+-------+ 3 rows in set (0.00 sec)
MySQL में प्राइमरी की ड्रॉप करने का क्वेरी निम्न है:
mysql> alter table DemoTable drop primary key; Query OK, 0 rows affected (1.70 sec) Records: 0 Duplicates: 0 Warnings: 0
आइए एक बार फिर टेबल विवरण जांचते हैं:
mysql> desc DemoTable;
इससे निम्न आउटपुट प्राप्त होगा:
+-------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+-------+ | StudentId | int(11) | NO | | NULL | | | StudentName | varchar(20) | YES | | NULL | | | StudentAge | int(11) | YES | | NULL | | +-------------+-------------+------+-----+---------+-------+ 3 rows in set (0.00 sec)