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);
CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT NOT NULL, email TEXT UNIQUE);
Check the meaning of 'SERIAL', 'PRIMARY KEY', 'NOT NULL', and 'UNIQUE' in SQL.
This command creates a table 'users' with 'id' as an auto-incrementing primary key, 'name' as a required text field, and 'email' as a unique text field. 'SERIAL' is supported in PostgreSQL, which Supabase uses.
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));
CREATE TABLE products (product_id INT PRIMARY KEY, name VARCHAR, price DECIMAL(10));In PostgreSQL, VARCHAR without a length specifier is valid and equivalent to TEXT.
In PostgreSQL, VARCHAR without length is valid (unlimited length, equivalent to TEXT). DECIMAL(10) is valid (precision 10, scale 0). The table is created successfully.
You want to create a table 'orders' in Supabase to store order data. Which option is the best design for the primary key column?
Consider uniqueness, scalability, and ease of use for primary keys.
UUIDs generated by gen_random_uuid() provide globally unique identifiers, avoid collisions, and are recommended for distributed systems like Supabase. Auto-increment integers can cause issues in distributed environments. Manual text keys risk duplicates. Composite keys add complexity.
Which practice helps prevent SQL injection when creating tables via Supabase SQL editor?
Think about how SQL injection happens and how to avoid it.
SQL injection occurs when user input is directly included in SQL commands. Using parameterized queries or predefined scripts avoids this risk. Manual escaping or regex sanitization is error-prone. Allowing users to write SQL is unsafe.
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?
DROP TABLE customers;
Consider how foreign key constraints affect dropping tables in PostgreSQL (used by Supabase).
PostgreSQL prevents dropping a table if other tables have foreign key constraints referencing it, unless you use CASCADE option. Without CASCADE, DROP TABLE fails with an error.