Blog
Database design problems and SQL Server errors, each solved step by step, with an example you can open in ERDsmith.
- DesignData modeling: what it is, types and a worked exampleData modeling is deciding the entities, attributes, relationships and rules a database holds. A bike rental modeled as tables, then as a star schema.
- Notation · RelationshipsIDEF1X notation: how to read an IDEF1X diagramIDEF1X is the FIPS 184 notation for relational data models. How to read an IDEF1X diagram symbol by symbol, with SQL Server tables of a university.
- DesignSQL Server data types: how to pick each column's typeSQL Server data types set what each column can hold. How to pick int or bigint, decimal, float or money, text, dates, bit or GUIDs, each one run on SQL Server.
- SQL Server errors · Design"String or binary data would be truncated" (Msg 2628, 8152)String or binary data would be truncated: SQL Server error 2628 or 8152 means a value is longer than its column. How to find the column, and the fixes.
- SQL Server errors · Relationships"The INSERT statement conflicted with the FOREIGN KEY constraint" (Msg 547)The INSERT statement conflicted with the FOREIGN KEY constraint: the row names a parent row that does not exist. The causes, a query that finds them, the fixes.
- Design · KeysDatabase naming conventions for SQL Server tables and keysDatabase naming conventions are the rules for naming tables, columns, keys and constraints. A set for SQL Server, and what breaks when SQL Server picks names.
- Designdatetime2 vs datetime in SQL Server: which one to usedatetime2 vs datetime: datetime rounds to 1/300 of a second and starts in 1753; datetime2 keeps up to 7 digits in 6 to 8 bytes. The traps, and which to use.
- Designnvarchar vs varchar in SQL Server: which to usenvarchar vs varchar: nvarchar stores Unicode, 2 bytes a character; varchar stores one code page, 1 byte. What each costs, and runs where data goes missing.
- RelationshipsON DELETE CASCADE in SQL Server: when to use itON DELETE CASCADE deletes the child rows when their parent row is deleted. How it differs from NO ACTION and SET NULL, and when a cascade deletes too much.
- Keys · DesignPrimary key column name: Id or CustomerId?Primary key column name: name it {Table}Id, such as CustomerId, not plain Id. What each choice does to joins, foreign keys, EF Core and role names.
- KeysSQL Server identity: IDENTITY_INSERT, SCOPE_IDENTITY, gapsA SQL Server identity column numbers rows from a seed and an increment. What it guarantees, where gaps come from, and how IDENTITY_INSERT and reseeding work.
- Relationships · KeysUnary relationship in SQL: the self-referencing foreign keyA unary relationship, or recursive relationship, links rows of a table to other rows of the same table. The SQL Server key, its diagram and what it refuses.
- Relationships · KeysCardinality in DBMS: the types and the SQL that sets themCardinality in DBMS is how many rows of one table can relate to one row of another. The four types, minimum and maximum, and the SQL behind each.
- Normalization · DesignDatabase normalization: 1NF, 2NF, 3NF and BCNF with SQLDatabase normalization splits tables so each fact is stored once. A school database taken through 1NF, 2NF, 3NF and BCNF, with the SQL and diagram of each.
- Normalization · DesignDenormalization: when to copy a value and when it's a bugDenormalization stores a value twice so reads skip a join. When a copy is the right design, when it is a bug waiting, and how SQL Server keeps a total in step.
- Design · RelationshipsER diagram to relational schema: 7 mapping rules in SQLER diagram to relational schema mapping turns entities, relationships and attributes into tables and keys. The seven rules, each with Chen, SQL and the tables.
- Design · RelationshipsHow to draw an ER diagram, from requirement to SQL tablesHow to draw an ER diagram from a plain-language requirement: entities, keys, relationships, a table for many-to-many, columns and a check, each step in SQL.
- Relationships · KeysJunction table: how to model many-to-many in SQL ServerA junction table, or bridge table, stores a many-to-many relationship as one row per pair. How to build one in SQL Server, its key, and the columns it grows.
- Relationships · DesignOne to one relationship in SQL Server, and one-to-manyA one to one relationship links each row to at most one row of another table. Both ways to build it in SQL Server, one-to-many beside it, and when to merge.
- NormalizationTransitive dependency: what it is and how 3NF removes itA transitive dependency is a non-key column that depends on the key only through another non-key column. Find one, see what it breaks, remove it for 3NF.
- Keys · RelationshipsWeak entity: owner, partial key and the SQL Server tableA weak entity has no key of its own: its owner's key plus a partial key identify it. How it becomes a SQL Server table, and what SQL Server refuses.
- Design · NotationWhat is an ER diagram? Parts, notations and an exampleWhat is an ER diagram? A picture of the entities a database stores, their keys and how they relate. The parts, three notations and the SQL behind one.
- Keys · RelationshipsComposite key: a key of two or more columns in SQL ServerA composite key is a key of two or more columns, usually the primary key. How SQL Server enforces it, how foreign keys reference it, when a surrogate fits.
- Notation · RelationshipsCrow's foot notation: the symbols and the SQL behind themCrow's foot notation marks each end of a relationship with how many rows it may hold. How to read each end, the SQL that gives it, and a cheat sheet.
- Notation · RelationshipsER diagram symbols: Chen, crow's foot and IDEF1XER diagram symbols in Chen, crow's foot and IDEF1X side by side: what each box, oval, diamond and line end means, and the SQL Server table it becomes.
- Keys · RelationshipsPrimary key vs foreign key: the difference, in SQL ServerPrimary key vs foreign key: a primary key uniquely identifies each row of its table, a foreign key points at it from another. What SQL Server checks on each.
- RelationshipsReferential integrity in SQL Server: keys and orphan rowsReferential integrity means every foreign key value points at a row that exists. How SQL Server enforces it, and how to find the orphan rows that slip past.
- Keys · DesignSurrogate key vs natural key: how to choose in SQL ServerSurrogate key vs natural key: a natural key comes from the data, a surrogate key is made up by the database. What each costs in SQL Server, and how to choose.
- KeysTypes of keys in DBMS: all eight in one airline schemaTypes of keys in DBMS: super, candidate, primary, alternate, foreign, composite, natural and surrogate keys, each shown in one airline schema in SQL Server.
- SQL Server errors · Keys"No primary or candidate keys in the referenced table" (Msg 1776)SQL Server error 1776, no primary or candidate keys in the referenced table, means a foreign key points at columns that are not a key. The fixes, with SQL.