O'Reilly logo

SQL Antipatterns by Bill Karwin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Antipattern: Format Comma-Separated Lists

To minimize changes to the database structure, you decide to redefine the account_id column as a VARCHAR so you can list multiple account IDs in that column, separated by commas.

Jaywalking/anti/create.sql
 
CREATE​ ​TABLE​ Products (
 
product_id SERIAL ​PRIMARY​ ​KEY​,
 
product_name ​VARCHAR​(1000),
 
account_id ​VARCHAR​(100), ​-- comma-separated list
 
-- . . .
 
);
 
 
INSERT​ ​INTO​ Products (product_id, product_name, account_id)
 
VALUES​ (​DEFAULT​, ​'Visual TurboBuilder'​, ​'12,34'​);

This seems like a win, because you’ve created no additional tables or columns; you’ve changed the data type of only one column. However, let’s look at the performance and data integrity problems this table ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required