MySQL: DEFAULT constraint is easy
Vložit
- čas přidán 27. 07. 2024
- #MySQL #course #tutorial
00:00:00 intro
00:02:25 DEFAULT when creating a table
00:03:26 DEFAULT for an existing table
00:05:19 example 2
00:07:56 conclusion
- EXAMPLE 1
CREATE TABLE products (
product_id INT,
product_name varchar(25),
price DECIMAL(4, 2) DEFAULT 0
);
ALTER TABLE products
ALTER price SET DEFAULT 0;
INSERT INTO products (product_id, product_name)
VALUES (104, "straw"),
(105, "napkin"),
(106, "fork"),
(107, "spoon");
SELECT * FROM products;
- EXAMPLE 2
CREATE TABLE transactions(
transaction_id INT,
amount DECIMAL(5, 2),
transaction_date DATETIME DEFAULT NOW()
);
SELECT * FROM transactions;
INSERT INTO transactions (transaction_id, amount)
VALUES (1, 4.99);
SELECT * FROM transactions;
INSERT INTO transactions (transaction_id, amount)
VALUES (2, 2.89);
SELECT * FROM transactions;
INSERT INTO transactions (transaction_id, amount)
VALUES (3, 8.37);
SELECT * FROM transactions;
DROP TABLE transactions;
- EXAMPLE 1
CREATE TABLE products (
product_id INT,
product_name varchar(25),
price DECIMAL(4, 2) DEFAULT 0
);
ALTER TABLE products
ALTER price SET DEFAULT 0;
INSERT INTO products (product_id, product_name)
VALUES (104, "straw"),
(105, "napkin"),
(106, "fork"),
(107, "spoon");
SELECT * FROM products;
- EXAMPLE 2
CREATE TABLE transactions(
transaction_id INT,
amount DECIMAL(5, 2),
transaction_date DATETIME DEFAULT NOW()
);
SELECT * FROM transactions;
INSERT INTO transactions (transaction_id, amount)
VALUES (1, 4.99);
SELECT * FROM transactions;
INSERT INTO transactions (transaction_id, amount)
VALUES (2, 2.89);
SELECT * FROM transactions;
INSERT INTO transactions (transaction_id, amount)
VALUES (3, 8.37);
SELECT * FROM transactions;
DROP TABLE transactions;
Thank you-excellent 🕊
Great!!
Please keep uploading videos of sql more & more
Dude, I was just thinking about trying Mysql today and you're releasing this video. Thank you very much!
Thank you for making these videos, they are easy to follow and understand.
Please continue the series❤
you're a Legend, thank you so much!!, that's so helpful!!!!
very easy to understand thanku
yeah
2:24 looks like you answered my question from a few videos ago.
you great!!!!!!
Kindly kindly Bro share us your Programming life journey or Q/A OR you interview and face revealed, love from Pakistan
Why did you use ALTER instead of MODIFY? 03:40
I also have this doubt
This would also work-
ALTER TABLE products
MODIFY price DECIMAL (5,2) DEFAULT 0.00;