SQL User Management – Create New Users Table or Use Built-In Database Management?

databasedatabase-designsql server

I am specifically interested in SQL Server, but the same question applies in general. When creating a new application, the way I see it, there are two options:

  • Create a table called "Users" and store the user name, password, etc. Set up one database user called "application" (and possibly more users for various components of the system).
  • Set up each application user as the database user. This may allow for easier single log on setup on Windows-based systems.

Which approach is generally preferred? Why? What are the drawbacks and benefits?

Best Answer

Another advantage of using the ad account or similar is that in your database itself you can run in built in functions to work out who is logged in. This can be useful for things like auditing, or to know who is accessing your database at any point in time using the tools provided by your database.

However as previously mentioned this doesn't scale particularly well. Lots of open connections on your database via different users is expensive in terms of server resource.

Using either scenario, for most larger apps, you're going to have a users table either way. Whichever authentication method you use, once you know who that user is you will likely need to know more about them - what their date if birth is, their nationality, financial authorisation limits, permission to click on the save button... Very often you will use a users table and associated tables to store whatever you need to know for the app.

Some frameworks, such as asp.net for example, provide tools that will automatically give you templates for maintaining your own user tables.