Given the table users(id SERIAL PRIMARY KEY, name TEXT DEFAULT 'Anonymous', age INT DEFAULT 18), what will be the content of the table after running this query?
INSERT INTO users DEFAULT VALUES;
CREATE TABLE users(id SERIAL PRIMARY KEY, name TEXT DEFAULT 'Anonymous', age INT DEFAULT 18); INSERT INTO users DEFAULT VALUES; SELECT * FROM users;
Think about what happens when you insert with DEFAULT VALUES and the table has default values defined.
The DEFAULT VALUES clause inserts a new row using all default values defined in the table. Since name and age have defaults, they are set accordingly. The id is auto-incremented by SERIAL.
Choose the correct SQL statement to insert a new row with all default values into a table products.
Remember the exact syntax for inserting default values without specifying columns.
The correct syntax to insert a row with all default values is INSERT INTO table DEFAULT VALUES;. Other options are invalid syntax.
Given the table orders(id SERIAL PRIMARY KEY, status TEXT DEFAULT 'pending', quantity INT DEFAULT 1), what will be the result of this query?
INSERT INTO orders(status, quantity) VALUES (DEFAULT, 5); SELECT * FROM orders;
CREATE TABLE orders(id SERIAL PRIMARY KEY, status TEXT DEFAULT 'pending', quantity INT DEFAULT 1); INSERT INTO orders(status, quantity) VALUES (DEFAULT, 5); SELECT * FROM orders;
Consider what DEFAULT means when used as a value in an INSERT statement.
Using DEFAULT as a value tells the database to use the column's default value. Here, status gets 'pending', and quantity is explicitly set to 5.
Given the table employees(id INT PRIMARY KEY, name TEXT DEFAULT 'John Doe'), why does this query fail?
INSERT INTO employees DEFAULT VALUES;
Check which columns require values and if they have defaults.
The 'id' column is NOT NULL and has no default value, so inserting default values without specifying 'id' causes an error.
Choose the best description of what INSERT INTO table DEFAULT VALUES; does.
Think about how default values work in SQL inserts.
The DEFAULT VALUES clause inserts a new row where each column is set to its default value if defined, otherwise NULL if allowed.