Schema Design & DDL Flashcards
CREATE, ALTER, DROP (tables, columns) Data types (PostgreSQL vs Oracle differences) Index creation syntax Unique constraints and composite keys Views and materialized views Sequences and identity columns Referential integrity (38 cards)
What does the CREATE statement do in SQL?
CREATE is used to define new database objects like tables, indexes, or views.
What does the ALTER statement do in SQL?
ALTER modifies the structure of an existing database object, such as adding a column to a table.
What does the DROP statement do in SQL?
DROP permanently deletes database objects like tables or indexes.
What are common data types in PostgreSQL?
INTEGER, SERIAL, TEXT, VARCHAR, BOOLEAN, TIMESTAMP, JSONB, UUID.
What are common data types in Oracle?
NUMBER, VARCHAR2, CLOB, BLOB, DATE, TIMESTAMP, RAW.
What is a key difference between PostgreSQL and Oracle data types?
PostgreSQL supports JSON/JSONB natively; Oracle relies on CLOB for similar use.
What is the syntax to create an index in SQL?
CREATE INDEX index_name ON table_name (column1, column2);
What is a unique constraint?
A constraint that ensures all values in a column or group of columns are unique.
What is a composite key?
A primary key made up of more than one column to uniquely identify a record.
What is a SQL view?
A virtual table representing the result of a stored query, not storing data physically.
What is a materialized view?
A view that stores the result set physically and can be refreshed periodically.
What is the difference between a view and a materialized view?
Views are virtual and always reflect current data; materialized views store data and can improve performance but may become stale.
What is a sequence in SQL?
A database object that generates a sequence of unique numeric values, often for primary keys.
What is an identity column in SQL?
A column that auto-increments its value using a built-in mechanism, replacing explicit sequences in some RDBMS.
What is referential integrity in databases?
Ensures relationships between tables remain consistent using foreign keys.
What is the advantage of using views?
Views provide abstraction, security, and simplified query logic.
What is a disadvantage of using views?
Views can become complex, hard to debug, and may impact performance if nested or improperly indexed.
What are best practices for schema design?
Use meaningful names, normalize where needed, enforce constraints, and plan indexing based on query patterns.
What is a use case for materialized views?
Caching aggregated reports or slow-running joins for faster access.
How do schema changes impact system design?
They affect API behavior, data migration, and require version control in CI/CD.
What is the impact of constraints on performance?
Constraints enforce data quality but add overhead during writes and updates.
What is an architectural implication of indexes?
Indexes improve read performance but can slow down inserts and updates, affecting write-heavy systems.
How do you monitor index usage?
Use database query plans, statistics views, and APM tools to identify index efficiency.
What is a real-world tradeoff in schema design?
Normalized schemas reduce redundancy but may require complex joins; denormalization simplifies reads but can cause anomalies.