Is it good database design to have admin users in the same table as front-end users?

Roles should be tracked separately from user accounts, because someone can be promoted (or demoted) over time. Would it make sense in that situation to have two different user accounts, in two different tables? I think not. Here’s the basic structure I’d use – USERS user_id (primary key) user_name ROLES role_id (primary key) role_name USER_ROLES … Read more

Primary key for multiple columns in PostgreSQL?

There can only be one primary key per table – as indicated by the word “primary”. You can have additional UNIQUE columns like: CREATE TABLE test( sl_no int PRIMARY KEY, — NOT NULL due to PK emp_id int UNIQUE NOT NULL, emp_name text, emp_addr text ); Columns that are (part of) the PRIMARY KEY are … Read more

How to choose between UUIDs, autoincrement/sequence keys and sequence tables for database primary keys?

UUIDs Unless these are generated “in increasing monotonic sequence” they can drastically hurt/fragment indexes. Support for UUID generation varies by system. While usable, I would not use a UUID as my primary clustered index/PK in most cases. If needed I would likely make it a secondary column, perhaps indexed, perhaps not. Some people argue that … Read more