Hello, What is the best way to design SQL SERVER with only one admin and a lot of users? I have 2 options:
This question might have been better to post to Stackoverflow. :-) When that is said, i will come with my opinion.
I would personally choose one table with role id. I think it's more sustainable, because it will be easy for you to add new roles in the future, by just adding a new role id.
You may not think, you ever will have a need for additional roles, but you can never know. Maybe your product-market-fit is totally different from what you create now, and here you have a need for additional roles.
Well, this dependence how you are going to query and design your database/table (index etc.).
2 You have only one admin, this means whenever you need admin's settings you will query one table that contains everything about admin. Since admin table contains only one entry even heap file still will be fast.
1 if we consider that your users table constantly expanding, it means each time whenever you look for an admin (the only one) you have to scan whole Users table unless you keep the table clustered sorted index on role_id. This can be costly if you (will) have many users, otherwise for early-stage startup this option will be easy for you so that you don't have to manage tables and make extra queries.
Option 1 for me but it's more because I've always done this way than because I have some real reason :-)
I've always gone with option 1 since there is likely to be a lot of overlap between the data for a user and for an admin (username, email, password, creation_date, etc...).
Yes all users should be on the same table with role IDs. You could also have an Admin table with a foreign key relationship to save Admin specific settings.
Are you going to query on those admin parameters?
If not, add a JSON column to the user table for the misc attributes. The added benefit is you've got a flexible schema for future user metadata. And modern DBs (PostgreSQL, at least) can even query on the JSON fields, if you really need to do that.
I will use admins parameters all over the project, for example the admin has "balance" and the user can buy max to the value of the admins "balance".