0
0
SQLquery~5 mins

INSERT with DEFAULT values in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the SQL statement INSERT INTO table_name DEFAULT VALUES; do?
It inserts a new row into table_name using all the default values defined for the columns. No specific values are provided.
Click to reveal answer
intermediate
Can you use INSERT INTO table_name DEFAULT VALUES; if the table has columns without default values and no NULL allowed?
No. If a column does not have a default value and does not allow NULL, the insert will fail because the database doesn't know what value to put.
Click to reveal answer
beginner
How do you insert a row with default values for some columns and specific values for others?
You specify the columns and values you want, and omit the others. The omitted columns will use their default values if defined.
Click to reveal answer
beginner
Why might using INSERT with DEFAULT VALUES be useful in real life?
It is useful when you want to add a new row but rely on the database to fill in standard values like timestamps, auto-increment IDs, or default status flags.
Click to reveal answer
intermediate
What happens if you try INSERT INTO table_name DEFAULT VALUES; on a table with no default values at all?
The insert will fail if any column requires a value and has no default or allows NULL. Otherwise, it inserts a row with NULLs where allowed.
Click to reveal answer
What does INSERT INTO users DEFAULT VALUES; do?
AUpdates existing rows with default values
BDeletes all rows from the users table
CInserts a new row with all columns set to their default values
DReturns an error always
If a column has no default and does not allow NULL, what happens when you use INSERT DEFAULT VALUES?
AThe database assigns a default value automatically
BThe insert succeeds with NULL in that column
CThe column gets a random value
DThe insert fails with an error
How can you insert a row with some columns using default values and others with specific values?
AUse <code>INSERT INTO table (col1, col2) VALUES (val1, DEFAULT);</code>
BUse <code>INSERT INTO table DEFAULT VALUES;</code> and then update
CYou cannot mix default and specific values in one insert
DUse <code>UPDATE</code> instead of <code>INSERT</code>
Which of these is a valid reason to use INSERT with DEFAULT VALUES?
ATo delete all rows in a table
BTo quickly add a row with system-generated values like timestamps
CTo update existing rows with default values
DTo select rows with default values
What is required for INSERT DEFAULT VALUES to work without error?
AAll columns must have default values or allow NULL
BAt least one column must have a default value
CThe table must be empty
DThe table must have a primary key
Explain how INSERT with DEFAULT VALUES works and when you would use it.
Think about adding a new record without specifying any data.
You got /4 concepts.
    What happens if you try to insert default values into a table with columns that have no defaults and do not allow NULL?
    Consider what the database needs to store a valid row.
    You got /3 concepts.