SQL in the Database Design Workflow

1

SQL in the Database Design Workflow

Building a well-structured relational database is never a single step. Before a single line of SQL is written, designers work through a progression of increasingly concrete decisions — from understanding what a business actually needs, to sketching out logical relationships, to finally specifying the exact storage and performance characteristics of the resulting system. SQL sits at the heart of that final step, acting as the language that converts carefully considered design artifacts into a real, running database. Understanding where SQL fits in this larger workflow explains why schemas are written the way they are, and why shortcuts taken early in design show up as costly problems later.

The database design process is traditionally divided into three distinct phases: conceptual design, logical design, and physical design. Each phase has a specific focus, a specific audience, and a specific output that feeds directly into the next phase.

Conceptual design is the starting point and operates entirely at the level of business understanding. During this phase, analysts work with stakeholders — business owners, end users, domain experts — to identify the key things the organization needs to track and the relationships between those things. These things are called entities, and their defining characteristics are called attributes. At this stage, there is no concern whatsoever for how data will be stored, what database system will be used, or even what data types columns might require. The goal is simply to capture a faithful picture of the business domain. The primary artifact produced during conceptual design is an Entity-Relationship (ER) diagram, which uses standardized notation to show entities as rectangles, attributes as ovals or listed properties, and relationships as connecting lines with cardinality markers. For example, a university system conceptual model might identify Student, Course, and Instructor as entities, and note that students enroll in courses while instructors teach them — without yet specifying how enrollment is tracked in a table.

Logical design takes the conceptual model and transforms it into a precise relational structure. Entities become candidate tables, attributes become columns, and the relationships identified in the ER diagram are translated into formal constructs such as primary keys, foreign keys, and junction tables. Normalization is applied during this phase to eliminate redundancy and ensure data integrity — typically working through first, second, and third normal forms. The logical model is still technology-agnostic: it does not reference a specific database system, does not assign physical storage parameters, and does not make performance decisions. It does, however, define every table name, every column name, the nature of every relationship (one-to-one, one-to-many, many-to-many), and the business rules that must be enforced. The output artifact is typically a relational schema diagram or a structured document listing each table with its columns and key constraints. This is the most direct input that SQL will eventually consume.

Physical design takes the logical schema and adapts it for a specific database management system (DBMS) and the real-world performance requirements of the application. Here, designers make decisions such as which columns use VARCHAR versus TEXT, where indexes should be placed to speed up common queries, how large tables will be partitioned, and whether certain data should be archived or compressed. Physical design also considers hardware constraints, expected data volumes, and query patterns. The output of physical design is a set of executable SQL statements — primarily DDL (Data Definition Language) — that can be run against the target DBMS to instantiate the schema exactly as designed.

The relationship between these three phases can be summarized as a pipeline:

Phase Primary Focus Key Questions Answered Output Artifact
Conceptual Business requirements and domain understanding What does the business need to track? What are the key entities? ER Diagram
Logical Relational structure and normalization How are entities represented as tables? What keys and relationships exist? Relational Schema / Schema Diagram
Physical DBMS-specific implementation and performance What data types, indexes, and storage settings are needed? Executable SQL DDL Scripts

SQL functions as the implementation layer of the entire design process — the point at which all earlier decisions are rendered in concrete, executable form. When a logical model says "a Student has a student ID, a first name, a last name, and an enrollment date," physical design answers the question of exactly how those facts are expressed in SQL:

CREATE TABLE student (
    student_id   INT           NOT NULL,
    first_name   VARCHAR(100)  NOT NULL,
    last_name    VARCHAR(100)  NOT NULL,
    enrolled_on  DATE          NOT NULL,
    CONSTRAINT pk_student PRIMARY KEY (student_id)
);

Every element of this statement has a traceable origin in the design phases that preceded it. The table name student comes from the entity identified in conceptual design. The column names and the decision that none of them can be null come from the logical model. The choice of INT, VARCHAR(100), and DATE is a physical design decision driven by the DBMS being used and the real-world data those fields will hold.

The primary SQL tool used during implementation is the family of Data Definition Language (DDL) statements: CREATE TABLE, ALTER TABLE, DROP TABLE, CREATE INDEX, and similar commands. These statements do not manipulate data — they define the structure within which data will live. DDL is what brings the schema into existence, and understanding DDL means understanding how design decisions get encoded into database objects.

The process of mapping a logical model to a SQL schema follows a set of well-established rules. Each entity in the logical model becomes a table. Each attribute of that entity becomes a column in that table. The data type of each column is determined during physical design based on the nature of the data the attribute represents and the constraints of the target DBMS.

Relationships require special handling in SQL because the relational model expresses relationships through data values — specifically, through foreign keys. A one-to-many relationship is implemented by placing a foreign key in the table on the "many" side that references the primary key of the table on the "one" side. For example, if many courses are taught by one instructor, the course table carries a foreign key pointing to the instructor table:

CREATE TABLE instructor (
    instructor_id  INT          NOT NULL,
    full_name      VARCHAR(150) NOT NULL,
    CONSTRAINT pk_instructor PRIMARY KEY (instructor_id)
);

CREATE TABLE course (
    course_id      INT          NOT NULL,
    title          VARCHAR(200) NOT NULL,
    instructor_id  INT          NOT NULL,
    CONSTRAINT pk_course        PRIMARY KEY (course_id),
    CONSTRAINT fk_course_instr  FOREIGN KEY (instructor_id)
                                REFERENCES instructor(instructor_id)
);

A many-to-many relationship cannot be expressed with a simple foreign key in either of the two participating tables, because one row cannot contain multiple values for a single column without violating first normal form. Instead, the logical model calls for a junction table (also called an associative table or bridge table) that holds the primary keys of both related tables as foreign keys. Each row in the junction table represents one specific pairing between the two entities. The student-course enrollment relationship is a classic example:

CREATE TABLE enrollment (
    student_id  INT  NOT NULL,
    course_id   INT  NOT NULL,
    CONSTRAINT pk_enrollment   PRIMARY KEY (student_id, course_id),
    CONSTRAINT fk_enroll_stud  FOREIGN KEY (student_id)
                               REFERENCES student(student_id),
    CONSTRAINT fk_enroll_cour  FOREIGN KEY (course_id)
                               REFERENCES course(course_id)
);

This junction table can also carry its own attributes — for instance, an enrolled_on date that records when a specific student enrolled in a specific course — making it a full entity in its own right.

SQL plays an equally important role in expressing design decisions as enforceable rules. The design process identifies many business rules that must always be true: a product must always have a price, no two users can share the same email address, a transaction amount cannot be negative. These rules, identified during conceptual and logical design, are encoded in SQL using constraints:

  • NOT NULL constraints enforce that a column must always carry a value, preventing the absence of required data. This directly implements a logical model decision that an attribute is mandatory rather than optional.
  • UNIQUE constraints enforce that no two rows can carry the same value in a specified column (or combination of columns), implementing uniqueness requirements identified in the logical model such as unique email addresses or employee badge numbers.
  • CHECK constraints enforce that column values satisfy a specified condition, translating domain-specific business rules directly into the database engine. For example, CHECK (price > 0) ensures no product can be recorded with a zero or negative price.
  • PRIMARY KEY constraints enforce entity integrity — the guarantee that every row in a table is uniquely identifiable. This is the SQL expression of the identifier attribute chosen in the logical model.
  • FOREIGN KEY constraints enforce referential integrity — the guarantee that every reference from one table to another points to a row that actually exists. This implements the relationship cardinality decisions made during logical design.

Consider a product pricing table where several business rules must be enforced simultaneously:

CREATE TABLE product (
    product_id    INT            NOT NULL,
    product_name  VARCHAR(255)   NOT NULL,
    sku           CHAR(10)       NOT NULL,
    unit_price    DECIMAL(10,2)  NOT NULL,
    category_id   INT            NOT NULL,
    CONSTRAINT pk_product        PRIMARY KEY (product_id),
    CONSTRAINT uq_product_sku    UNIQUE (sku),
    CONSTRAINT chk_price_pos     CHECK (unit_price > 0),
    CONSTRAINT fk_product_cat    FOREIGN KEY (category_id)
                                 REFERENCES category(category_id)
);

Each constraint here is not arbitrary SQL syntax — it is the direct expression of a decision made earlier in the design process. The UNIQUE on sku came from the logical model's declaration that SKUs are alternate keys. The CHECK on unit_price came from a business rule captured during conceptual design. The FOREIGN KEY on category_id came from the one-to-many relationship identified between categories and products.

Schema organization — how tables are grouped, named, and arranged within a database — is another dimension where SQL reflects design intent. Many DBMS platforms support schemas (namespaces within a database) that allow tables to be grouped by functional area. A large enterprise system might separate its tables into schemas named hr, finance, inventory, and sales, mirroring the conceptual boundaries established during the earliest phase of design. Table and column naming conventions carry the same semantics as the entity and attribute names in the ER diagram, making the schema self-documenting and traceable back to the original business requirements.

One of the most important practical realities in database design is that the process is iterative rather than strictly linear. Writing SQL schemas has a unique ability to surface problems in the logical model that are invisible when working at the diagram level. For example, a logical model might show a relationship between two entities that appears clean in an ER diagram, but when the designer attempts to write the corresponding SQL, they realize that referential integrity cannot be enforced in the intended direction without a circular dependency that prevents either table from being created first. Similarly, a CHECK constraint that seems straightforward may reveal that the business rule it encodes was actually ambiguous — does "price must be positive" mean strictly greater than zero, or does it allow zero for free items?

Performance testing at the physical layer can also send the design back to logical decisions. If a heavily normalized schema results in queries that require joining eight tables to retrieve a single meaningful report, a designer might revisit the normalization level — consciously introducing a degree of controlled redundancy to improve read performance, then documenting that decision so future maintainers understand the trade-off. This is called denormalization, and it is always a deliberate, documented choice rather than a careless omission of normalization rules.

Maintaining alignment between design documentation and the SQL schema as a system evolves is one of the most commonly neglected aspects of database management. Over time, development teams add columns, rename tables, drop obsolete relationships, and introduce new constraints — often directly in the SQL without updating the original ER diagrams or schema documents. This leads to a situation where the documentation describes a different system than the one actually running in production, making future changes difficult and error-prone. Best practices include treating schema migration scripts as formal artifacts (using tools like Flyway or Liquibase to version-control schema changes), updating ER diagrams whenever the schema changes, and reviewing both the documentation and the DDL together during design review sessions.

Taken together, these principles establish a clear picture: SQL is not just a querying language, and writing a CREATE TABLE statement is not merely a technical task. Each SQL statement is the accumulated result of requirements gathering, conceptual modeling, relational theory, normalization, and physical planning. When a developer writes a schema that lacks foreign keys, omits NOT NULL where values are required, or collapses multiple distinct entities into a single table out of convenience, they are not just making SQL mistakes — they are abandoning the design decisions that those SQL features were built to express. Understanding SQL in the context of the full design workflow is what separates schemas that are merely functional from schemas that are correct, maintainable, and aligned with the real needs of the systems they support.

NotesThe topic content covers all five subtopic clusters in depth: the three-phase model with artifact pipeline table, SQL as the DDL-based implementation layer, entity/relationship-to-table/foreign-key/junction-table mapping with worked examples, constraint types as encoded business rules, and iterative refinement including denormalization and schema-documentation alignment. Code examples use ANSI-compatible SQL and are deliberately traceable back to the design decisions described in the prose.