Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7014729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:33:34+00:00 2026-05-27T22:33:34+00:00

I have a table called Request and data will be entered by two types

  • 0

I have a table called Request and data will be entered by two types of users (Company staff and site members). Initially I had a column called createdby. But, the staff and the members table primary keys are integers with identity. So i had to change it because there could be an ID that corresponds to both entities.

Then I have created two columns in the the request table ByStaffId and ByMemberID. I wonder whether it is the right way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:33:34+00:00Added an answer on May 27, 2026 at 10:33 pm

    Below is an example of how to relate the Staff and Members together using a common User table that has a 1-to-1 relationship with both a StaffUser table and a MemberUser table.

    Granted, this approach results in greater complexity when selecting/inserting/updating/deleting users, so you can decide whether this is worth the extra complexity.

    create table [User]
    (
        UserID int identity(1,1) not null primary key,
        Username nvarchar(50) not null
    )
    
    create table StaffUser
    (
        UserID int not null primary key references [User] (UserID),
        FirstName nvarchar(50) not null,
        LastName nvarchar(50) not null
    )
    
    create table MemberUser
    (
        UserID int not null primary key references [User] (UserID),
        Email nvarchar(100) not null,
    )
    
    create table Request
    (
        ByUserID int not null references [User] (UserID),
    )
    
    declare @UserID int
    
    insert into [User] values ('john.smith')
    set @UserID = scope_identity()
    insert into StaffUser values (@UserID, 'John', 'Smith')
    
    insert into Request values (@UserID)
    
    insert into [User] values ('billy.bob')
    set @UserID = scope_identity()
    insert into StaffUser values (@UserID, 'Billy', 'Bob')
    
    insert into Request values (@UserID)
    
    insert into [User] values ('member1')
    set @UserID = scope_identity()
    insert into MemberUser values (@UserID, 'member1@awesome.com')
    
    insert into Request values (@UserID)
    
    insert into [User] values ('member2')
    set @UserID = scope_identity()
    insert into MemberUser values (@UserID, 'member2@awesome.com')
    
    insert into Request values (@UserID)
    
    insert into [User] values ('member3')
    set @UserID = scope_identity()
    insert into MemberUser values (@UserID, 'member3@awesome.com')
    
    insert into Request values (@UserID)
    
    -- select staff
    select
        StaffUser.UserID,
        [User].Username,
        StaffUser.FirstName,
        StaffUser.LastName
    from StaffUser
    inner join [User] on
        [User].UserID = StaffUser.UserID
    
    -- select members
    select
        MemberUser.UserID,
        [User].Username,
        MemberUser.Email
    from MemberUser
    inner join [User] on
        [User].UserID = MemberUser.UserID
    
    
    -- select all users
    select
        StaffUser.UserID,
        [User].Username
    from StaffUser
    inner join [User] on
        [User].UserID = StaffUser.UserID
    
    union all
    
    select
        MemberUser.UserID,
        [User].Username
    from MemberUser
    inner join [User] on
        [User].UserID = MemberUser.UserID
    
    
    select * from Request
    
    
    drop table Request
    drop table MemberUser
    drop table StaffUser
    drop table [User]
    

    Below is a slightly more complicated structure that accomplishes the same thing as the example above, but in this case Member and Staff are more decoupled from User.

    create table [User]
    (
        UserID int identity(1,1) not null primary key,
        CreatedOn datetime not null default getdate()
    )
    
    create table StaffUser
    (
        UserID int not null primary key references [User] (UserID)
    )
    
    create table MemberUser
    (
        UserID int not null primary key references [User] (UserID)
    )
    
    create table Staff
    (
        StaffID int identity(1,1) not null primary key,
        FirstName nvarchar(50) not null,
        LastName nvarchar(50) not null,
        UserID int null references StaffUser (UserID),
    )
    
    create table Member
    (
        MemberID int identity(1,1) not null primary key,
        Username nvarchar(50),
        Email nvarchar(100) not null,
        UserID int null references MemberUser (UserID),
    )
    
    create table Request
    (
        ByUserID int not null references [User] (UserID),
    )
    
    declare @UserID int
    
    insert into [User] default values
    set @UserID = scope_identity()
    insert into StaffUser values (@UserID)
    insert into Staff values ('John', 'Smith', @UserID)
    
    insert into Request values (@UserID)
    
    insert into [User] default values
    set @UserID = scope_identity()
    insert into StaffUser values (@UserID)
    insert into Staff values('Billy', 'Bob', @UserID)
    
    insert into Request values (@UserID)
    
    insert into [User] default values
    set @UserID = scope_identity()
    insert into MemberUser values (@UserID)
    insert into Member values ('member1', 'member1@awesome.com', @UserID)
    
    insert into Request values (@UserID)
    
    insert into [User] default values
    set @UserID = scope_identity()
    insert into MemberUser values (@UserID)
    insert into Member values ('member2', 'member2@awesome.com', @UserID)
    
    insert into Request values (@UserID)
    
    insert into [User] default values
    set @UserID = scope_identity()
    insert into MemberUser values (@UserID)
    insert into Member values ('member3', 'member3@awesome.com', @UserID)
    
    insert into Request values (@UserID)
    
    -- select staff
    select
        Staff.StaffID,
        Staff.FirstName,
        Staff.LastName,
        Staff.UserID
    from Staff
    
    -- select members
    select
        Member.MemberID,
        Member.Username,
        Member.Email,
        Member.UserID
    from Member
    
    -- select all users
    select
        [User].UserID,
        Staff.FirstName + ' ' + Staff.LastName as Name,
        [User].CreatedOn
    from [User]
    inner join Staff on
        Staff.UserID = [User].UserID
    
    union all
    
    select
        [User].UserID,
        Member.Username as Name,
        [User].CreatedOn
    from [User]
    inner join Member on
        Member.UserID = [User].UserID
    
    
    select * from Request
    
    
    drop table Request
    drop table Member
    drop table Staff
    drop table MemberUser
    drop table StaffUser
    drop table [User]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called Request and the data looks like: Req_ID R1 R2
I have a table called ProjectRegion. It has two columns, an id and a
Consider the following data model: Suppose I have a table called SuperAwesomeData where each
I have two database tables. One table stores data for a commitment that a
I have a table called users which currently contains column money of type integer
I have table called stats . In am inserting yes or no in the
I have a table called OffDays, where weekends and holiday dates are kept. I
I have a Table called Product and I have the Table StorageHistory . Now,
I have a table called ApprovalTasks... Approvals has a status column I also have
I have a table called BlogPost which has a 1-to-many relationship with the Comment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.