0
0
Supabasecloud~20 mins

Creating tables via SQL editor in Supabase - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SQL Table Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding SQL Table Creation Syntax

What will be the result of running this SQL command in Supabase SQL editor?

CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT NOT NULL, email TEXT UNIQUE);
Supabase
CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT NOT NULL, email TEXT UNIQUE);
AA table named 'users' is created but 'email' column allows duplicate values.
BA new table named 'users' is created with three columns: 'id' as auto-incrementing primary key, 'name' as required text, and 'email' as unique text.
CAn error occurs because 'SERIAL' is not supported in Supabase SQL editor.
DThe table is created but 'id' column is not set as primary key.
Attempts:
2 left
💡 Hint

Check the meaning of 'SERIAL', 'PRIMARY KEY', 'NOT NULL', and 'UNIQUE' in SQL.

Configuration
intermediate
2:00remaining
Identifying Error in Table Creation

What error will this SQL command produce when run in Supabase SQL editor?

CREATE TABLE products (product_id INT PRIMARY KEY, name VARCHAR, price DECIMAL(10));
Supabase
CREATE TABLE products (product_id INT PRIMARY KEY, name VARCHAR, price DECIMAL(10));
AError because PRIMARY KEY cannot be assigned to INT type.
BError because DECIMAL requires two parameters for precision and scale.
CSyntax error because VARCHAR requires a length specification.
DTable created successfully with columns 'product_id', 'name', and 'price'.
Attempts:
2 left
💡 Hint

In PostgreSQL, VARCHAR without a length specifier is valid and equivalent to TEXT.

Architecture
advanced
2:00remaining
Choosing Best Primary Key Design

You want to create a table 'orders' in Supabase to store order data. Which option is the best design for the primary key column?

AUse a column 'order_id' with type UUID generated by default with gen_random_uuid() function.
BUse a composite primary key of 'user_id' and 'order_date' columns.
CUse a text column 'order_code' where users manually enter unique codes.
DUse an integer column 'order_number' with auto-increment (SERIAL) as primary key.
Attempts:
2 left
💡 Hint

Consider uniqueness, scalability, and ease of use for primary keys.

security
advanced
2:00remaining
Preventing SQL Injection in Table Creation Scripts

Which practice helps prevent SQL injection when creating tables via Supabase SQL editor?

ANever accept user input directly in SQL commands; use parameterized queries or predefined scripts.
BEscape all single quotes in user input manually before inserting into SQL commands.
CUse dynamic SQL concatenation with user input but sanitize inputs with regex.
DAllow users to write their own SQL commands to create tables for flexibility.
Attempts:
2 left
💡 Hint

Think about how SQL injection happens and how to avoid it.

service_behavior
expert
2:00remaining
Effect of Dropping a Table with Dependent Foreign Keys

Given two tables in Supabase:

CREATE TABLE customers (id UUID PRIMARY KEY, name TEXT); CREATE TABLE orders (id UUID PRIMARY KEY, customer_id UUID REFERENCES customers(id));

What happens if you run DROP TABLE customers; without any additional options?

Supabase
DROP TABLE customers;
AThe 'customers' table is dropped and 'orders' table remains unchanged with broken foreign key references.
BThe 'customers' table is dropped and foreign key constraints in 'orders' are automatically removed.
CThe command fails with an error because 'orders' table depends on 'customers' via foreign key.
DThe 'customers' table is dropped and all rows in 'orders' with matching customer_id are automatically deleted.
Attempts:
2 left
💡 Hint

Consider how foreign key constraints affect dropping tables in PostgreSQL (used by Supabase).