DROP TABLE IF EXISTS referred, refer;
CREATE TABLE referred (
id int PRIMARY KEY AUTO_INCREMENT
);
CREATE TABLE refer (
id int PRIMARY KEY AUTO_INCREMENT,
id_referred int NOT NULL,
CONSTRAINT id_referred FOREIGN KEY (id_referred) REFERENCES referred (id)
);
SELECT CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME
FROM information_schema.KEY_COLUMN_USAGE
WHERE TABLE_NAME = "refer";
CONSTRAINT_NAME	TABLE_NAME	COLUMN_NAME
PRIMARY	refer	id
id_referred	refer	id_referred
DROP TABLE refer;
DROP TABLE referred;
