Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To create a database from scratch, first decide what information your application must keep, then organize it into related tables with defined columns, keys, and rules. SQL lets you create that structure, add and change rows, and retrieve information. This guide explains the design choices to make before you build, using relational databases as the model.

What a relational database does

A relational database stores information in tables. Each table represents a subject, each row represents one instance of that subject, and each column records an attribute. Relationships connect rows across tables. SQL is the language commonly used to define tables, insert and update data, and query it.

PostgreSQL’s introductory tutorial covers relational concepts and SQL, including joins, foreign keys, and transactions: PostgreSQL tutorial. Microsoft’s T-SQL tutorial introduces creating a database and table, inserting and updating rows, and reading data: Microsoft Learn T-SQL tutorial. SQL syntax and available features can differ by database engine, so treat examples as concepts until you choose an engine.

Start with the information you need to store

Write down the real-world subjects your application handles, such as people, courses, orders, or products. Give each independent subject its own table, then list the attributes that belong to it. Microsoft’s design guidance recommends separating information into subject-based tables, and its Azure SQL example uses Person, Student, Course, and Credit tables to show how related data can be structured.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For example, in a course system, a Person table might hold a person’s name and contact details, while a Course table holds a course title and code. A Student table can represent the student role or record, rather than repeating the person’s name every time that person enrolls. The right boundaries depend on the application’s rules: distinguish entities when their information is independently meaningful or changes independently.

Choose columns, types, and required-value rules

For each table, decide which columns it needs and what values each can contain. Use a data type suitable for the value—such as a number, text, date, or true/false value—and decide whether the value may be absent. A column that must always be supplied should be declared NOT NULL; an optional value may allow NULL.

Constraints let the database enforce rules instead of relying only on application code. Common choices include:

  • PRIMARY KEY: identifies each row uniquely.
  • FOREIGN KEY: restricts a relationship to a key that exists in the referenced table.
  • NOT NULL: requires a value for a column.
  • UNIQUE: prevents duplicate values where a business rule requires uniqueness, such as a course code.
  • CHECK: limits values to an allowed condition or range.

Microsoft’s Azure SQL tutorial demonstrates NOT NULL, UNIQUE, CHECK, and foreign-key definitions in table creation: Azure SQL database design tutorial. Add constraints when they express real rules; do not impose a limit merely because it seems convenient.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use primary keys to identify rows

A primary key is one column or a combination of columns whose value is unique for every row. It gives the database and other tables a stable way to refer to a specific record. Microsoft Learn notes that most tables have a primary key made from one or more columns: Microsoft Learn T-SQL tutorial.

A single-column key is often straightforward, especially when a table has a dedicated identifier such as PersonId. A composite key uses multiple columns when only their combination identifies a row. For instance, if a student can take a course only once, StudentId and CourseId together could identify an enrollment. Choose a key based on the actual uniqueness rule, not on a guess about what values happen to be unique in today’s sample data.

Connect tables with foreign keys

A foreign key stores a value that references a key in another table. For example, Student.PersonId can reference Person.PersonId. Person is then the parent table for that relationship, and Student is the dependent or child table. The constraint helps prevent a student record from referring to a person row that does not exist.

Foreign keys describe the intended relationship in the data model; they do not by themselves determine every business rule. Decide whether a child record is required, whether one parent may have many children, and what should happen when a referenced record changes or is removed. Define those behaviors deliberately in the chosen engine rather than assuming all systems handle them identically. Microsoft’s database design guidance discusses primary and foreign keys, while its Azure SQL example shows their table definitions: Microsoft Support: Database design basics.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Normalize to avoid conflicting copies of facts

Normalization is a way to structure tables so each fact is stored in an appropriate place rather than repeated in multiple rows. If a customer’s address is copied into every order row, changing the address can leave old and new copies inconsistent. Storing customer details in a customer table and referring to that customer from orders reduces that kind of update anomaly.

Do not split data into tables simply to maximize table count. Separate facts when they belong to different subjects or can change independently, then connect the tables with keys. More normalized designs can require more joins to assemble a result; designs that duplicate mutable facts may be easier to query in some cases but are harder to keep consistent. Microsoft recommends applying normalization rules in its design guidance, and OpenStax explains second normal form as requiring first normal form and requiring every nonkey column to depend on the whole primary key: OpenStax database design.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Build and check a first version

  1. Choose a database engine and create an empty database. PostgreSQL, SQL Server, and other relational engines use SQL, but details of their commands and types vary.
  2. Create parent tables before dependent tables. Define primary keys first, then create tables whose foreign keys refer to them.
  3. Insert representative rows. Include ordinary values and edge cases, such as an optional field with no value, to check that the schema reflects the rules you intended.
  4. Run SELECT queries and joins. Confirm that filtering, sorting, and joining related tables returns the expected records, including cases where related rows are absent if that is allowed.
  5. Extend the design as the project requires. Indexes, permissions, transactions, and a repeatable migration process matter as the application grows; they are separate concerns from deciding which facts belong in which tables.

Microsoft’s T-SQL tutorial provides a create, insert, update, and read path, while the PostgreSQL tutorial introduces joins, foreign keys, and transactions. Use the tutorial for your selected engine when translating the design into executable SQL.

What to decide before adding complexity

When comparing possible schemas, assess their table boundaries, key strategy, relationship cardinality, normalization level, constraint coverage, and fit with the SQL dialect of your database engine. First make the data rules clear; performance tuning is a later step, not a substitute for a sound model.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.