how to map primary id to column mysql python code example
Example 1: mysql change primary key
ALTER TABLE tableName MODIFY COLUMN id INT;
ALTER TABLE tableName DROP PRIMARY KEY;
ALTER TABLE tableName ADD PRIMARY KEY (new_id);
ALTER TABLE tableName MODIFY COLUMN new_id INT AUTO_INCREMENT;
Example 2: MySql get primary keys of table
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'Your Database'
AND TABLE_NAME = 'Your Table name'
AND COLUMN_KEY = 'PRI';
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'Your Database'
AND TABLE_NAME = 'Your Table name'
AND COLUMN_KEY = 'UNI';