UNIQUE
Unique
CREATE TABLE IF NOT EXISTS `course`(
`course_id` CHAR(12) NOT NULL,
`course_code` VARCHAR(40) NOT NULL UNIQUE,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
)
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL UNIQUE,
`course_code` VARCHAR(7) NOT NULL UNIQUE,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
);
SHOW INDEX FROM `course`;
Unique
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5)),
UNIQUE(`course_code`)
);
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5)),
UNIQUE(`course_id`),
UNIQUE(`course_code`)
);
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5)),
UNIQUE(`course_id`, `course_code`)
);
SHOW INDEX FROM `course`;
Unique Key
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5)),
UNIQUE KEY(`course_code`)
);
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5)),
UNIQUE KEY `uc_course_code`(`course_code`)
);
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5)),
UNIQUE KEY `uc_course_id`(`course_id`),
UNIQUE KEY `uc_course_code`(`course_code`)
);
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5)),
UNIQUE KEY `uc_course_id_code`
(`course_id`, `course_code`)
);
SHOW INDEX FROM `course`;
Constraint Unique
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5)),
CONSTRAINT UNIQUE(`course_code`)
);
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5)),
CONSTRAINT `uc_course_code` UNIQUE (`course_code`)
);
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5)),
CONSTRAINT `uc_course_id` UNIQUE (`course_id`),
CONSTRAINT `uc_course_code` UNIQUE (`course_code`)
);
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5)),
CONSTRAINT `uc_course_id_code`
UNIQUE (`course_id`, `course_code`)
);
SHOW INDEX FROM `course`;
Alter Table + Unique
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
);
ALTER TABLE `course` ADD UNIQUE(`course_code`);
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
);
ALTER TABLE `course` ADD UNIQUE(`course_id`);
ALTER TABLE `course` ADD UNIQUE(`course_code`);
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
);
ALTER TABLE `course` ADD
UNIQUE(`course_id`, `course_code`);
SHOW INDEX FROM `course`;
Alter Table + Unique Key
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
);
ALTER TABLE `course` ADD
UNIQUE KEY `uc_course_code` (`course_code`);
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
);
ALTER TABLE `course` ADD
UNIQUE KEY `uc_course_id` (`course_id`);
ALTER TABLE `course` ADD
UNIQUE KEY `uc_course_code` (`course_code`);
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
);
ALTER TABLE `course` ADD UNIQUE KEY
`uc_course_id_code` (`course_id`, `course_code`);
SHOW INDEX FROM `course`;
Alter Table + Constraint
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
);
ALTER TABLE `course` ADD
CONSTRAINT UNIQUE (`course_code`);
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
);
ALTER TABLE `course` ADD CONSTRAINT
`uc_course_code` UNIQUE (`course_code`);
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
);
ALTER TABLE `course` ADD CONSTRAINT
`uc_course_id` UNIQUE (`course_id`);
ALTER TABLE `course` ADD CONSTRAINT
`uc_course_code` UNIQUE (`course_code`);
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
);
ALTER TABLE `course` ADD CONSTRAINT `uc_course_id_code`
UNIQUE (`course_id`, `course_code`);
SHOW INDEX FROM `course`;
Create Unique Index
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
);
CREATE UNIQUE INDEX `uc_course_code`
ON `course` (`course_code`);
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
);
CREATE UNIQUE INDEX `uc_course_id`
ON `course` (`course_id`);
CREATE UNIQUE INDEX `uc_course_code`
ON `course` (`course_code`);
SHOW INDEX FROM `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
);
CREATE UNIQUE INDEX `uc_course_id_code`
ON `course` (`course_id`, `course_code`);
SHOW INDEX FROM `course`;
Drop Index
DROP TABLE IF EXISTS `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL UNIQUE,
`course_code` VARCHAR(7) NOT NULL UNIQUE,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
);
SHOW INDEX FROM `course`;
DROP INDEX `course_id` ON `course`;
SHOW INDEX FROM `course`;
DROP INDEX `course_code` ON `course`;
SHOW INDEX FROM `course`;
DROP TABLE IF EXISTS `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
);
CREATE UNIQUE INDEX `uc_course_id_code`
ON `course` (`course_id`, `course_code`);
SHOW INDEX FROM `course`;
DROP INDEX `uc_course_id_code` ON `course`;
SHOW INDEX FROM `course`;
Drop Index + Alter Table
DROP TABLE IF EXISTS `course`;
CREATE TABLE IF NOT EXISTS `course`(
`course_id` INT(11) NOT NULL,
`course_code` VARCHAR(7) NOT NULL,
`course_title` VARCHAR(40) NOT NULL,
`course_dept` VARCHAR(4) NOT NULL,
`course_credit` FLOAT(3,1)
CHECK (`course_credit` IN (3.0, 1.5))
);
CREATE UNIQUE INDEX `uc_course_id`
ON `course` (`course_id`);
CREATE UNIQUE INDEX `uc_course_code`
ON `course` (`course_code`);
SHOW INDEX FROM `course`;
ALTER TABLE `course` DROP INDEX `uc_course_id`;
SHOW INDEX FROM `course`;
ALTER TABLE `course` DROP INDEX `uc_course_code`;
SHOW INDEX FROM `course`;
Last updated
Was this helpful?