Script Valley
Database Design: From Idea to Schema
Data Types and Constraints/Assessment

Practice & Assessment

Test your understanding of Data Types and Constraints

Multiple Choice Questions

5
1

Which data type should you use to store a monetary amount like 19.99?

2

A query SELECT * FROM users WHERE email = NULL returns zero rows even though some rows have NULL email. Why?

3

When should you use ON DELETE CASCADE on a foreign key?

4

Which column is the worst candidate for a standalone index?

5

What is the correct way to ensure no two rows in the users table have the same email address?

Coding Challenges

1
1

Design the Schema for an E-Commerce Product Catalog

Write CREATE TABLE statements for a product catalog with: products (id, name, sku, price, stock, status, created_at), categories (id, name, slug), and a product_categories junction. Requirements: price must be positive; sku must be unique; status must be one of 'active', 'inactive', 'discontinued'; stock defaults to 0 and cannot be negative; category slug must be unique and lowercase enforced by a CHECK. Include all PKs, FKs, constraints, and appropriate data types. Time estimate: 25 minutes.

Medium

Mini Project

1

Constrained Schema for a Hotel Booking System

Design and write full DDL for a hotel booking system covering: hotels, room_types, rooms, guests, bookings, and payments. Every table must have correct data types for all columns, NOT NULL where appropriate, UNIQUE constraints on natural keys, CHECK constraints on price/amount/status columns, appropriate FK ON DELETE behavior for each relationship, indexes on all FK columns, and a TIMESTAMP created_at on every table. Document each constraint choice with an inline SQL comment.

Hard
Practice & Assessment โ€” Data Types and Constraints โ€” Database Design: From Idea to Schema โ€” Script Valley โ€” Script Valley