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.

​ ​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 ...

Get SQL Antipatterns, Volume 1 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.