MySQL: UNIQUE constraint

Author: Bro Code
Published At: 2022-10-18T00:00:00
Length: 04:43

Summary

Description

#MySQL #tutorial #course

00:00:00 add UNIQUE CONSTAINT to a new table

00:01:12 add UNIQUE CONSTAINT to an existing table

00:02:00 demonstration

CREATE TABLE products (

product_id INT,

product_name varchar(25) UNIQUE,

price DECIMAL(4, 2)

);

ALTER TABLE products

ADD CONSTRAINT

UNIQUE (product_name);

INSERT INTO products

VALUES (100, 'hamburger', 3.99),

(101, 'fries', 1.89),

(102, 'soda', 1.00),

(103, "ice cream", 1.49);

SELECT * FROM products;

Translated At: 2025-02-23T11:27:38Z

Request translate (One translation is about 5 minutes)

Version 3 (stable)

Optimized for a single speaker. Suitable for knowledge sharing or teaching videos.

Recommended Videos