Saving login details in SQL Server database

I am new to programming.

I am creating a project in which i want to store login details into database but i am using Combobox list because there are various types of user and for that particular selected user i want to get the info store in my database.

My form looks like this...

  • User Id : Textbox
  • Password : Textbox
  • User Type : ComboBoxlist

In that comboboxlist there are 3 types of users.

So, how do I store the above mentioned details of login into my database?

I hope I have framed the question in the right way...:)

Thank you

1 answer

  • answered 2018-01-14 07:44 Jayasurya Satheesh

    Try a Database Design With 3 Tables.

    1. User Table - Store User Login Information
    2. Roles Table - Store Available Roles in the System
    3. User Roles - Store Roles assigned to each user

    something like this

    User Table

    CREATE TABLE dbo.Users
    (
        UserId INT IDENTITY(1,1) CONSTRAINT Pk_Users_UserI PRIMARY KEY CLUSTERED,
        UserNm VARCHAR(255) NOT NULL CONSTRAINT Uq_Users_UserNm UNIQUE,
        FirstNm VARCHAR(50) NOT NULL,
        LastNm VARCHAR(50) NOT NULL,
        Email VARCHAR(255),
        Pwd NVARCHAR(1000)
    )
    

    Roles Table

    CREATE TABLE dbo.Roles
    (
        RoleId INT IDENTITY(1,1) CONSTRAINT Pk_Roles_RoleId PRIMARY KEY CLUSTERED,
        RoleCd VARCHAR(10) NOT NULL CONSTRAINT Uq_Roles_RoleCd UNIQUE,
        RoleNm VARCHAR(255)
    )
    

    User Roles

    CREATE TABLE dbo.UserRoles 
    (
        UserRoleId INT IDENTITY(1,1) CONSTRAINT Pk_UserRoles_UserRoleId PRIMARY KEY CLUSTERED,
        UserId INT NOT NULL CONSTRAINT Fk_UserRoles_UserId FOREIGN KEY REFERENCES dbo.Users(UserId),
        RoleId INT NOT NULL CONSTRAINT Fk_UserRoles_RoleId FOREIGN KEY REFERENCES dbo.Roles(Roleid)
    )