What is DEFAULT ?
What is DEFAULT ?
DEFAULT is a column constraint that supplies a value when an INSERT does not provide one for that column.
CREATE TABLE orders (
id BIGINT PRIMARY KEY,
status VARCHAR(20) NOT NULL DEFAULT 'pending',
quantity INT NOT NULL DEFAULT 1,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO orders (id) VALUES (1); -- uses all defaults
INSERT INTO orders (id, status) VALUES (2, DEFAULT); -- explicit DEFAULT keyword
INSERT INTO orders (id, status) VALUES (3, NULL); -- NULL is NOT replaced by the default
DEFAULT. Passing NULL explicitly stores NULL (and fails on a NOT NULL column).Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.