Share via

SQL Server List Box in one field/ table referencing items located in another field/ table?

Andrew Wolf 0 Reputation points
2024-01-11T15:48:00.77+00:00

How does one create a list box in a field (Table A) with items referencing a field in table B so that the user updating the table is able to select from the items? I'm hoping there is a non C# writing method (just using the SQL Server features). What is the most simple solution? Very much appreciate your help and guidance! Thanks- Andrew

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories

0 comments No comments

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 134.7K Reputation points MVP Volunteer Moderator
    2024-01-11T22:19:48.2133333+00:00

    You can't do that with only SQL Server features. SQL Server is not a UI tool, and it does not have a UI itself. That does not mean that you need to use C#; there are plenty of other environments: Java, Delphi, Access and probably a few more.

    Was this answer helpful?

    0 comments No comments

  2. Azar 31,720 Reputation points MVP Volunteer Moderator
    2024-01-11T15:59:31.81+00:00

    Hi Andrew Wolf

    You can use a foreign key relationship to create a list box in a field (Table A) referencing items from another field (Field B) in another table.

    add these

    Table A: Add a field (ForeignKeyReference) for the foreign key.

    Table B: Has a field (ForeignKeyField) containing reference items.

    Create Foreign Key Relationship, Link Table A.ForeignKeyReference to Table B.ForeignKeyField. for UI Dropdown In your UI, use a dropdown or combo box for ForeignKeyReference. now populate the dropdown dynamically from distinct values in Table B.ForeignKeyField.

    SELECT DISTINCT ForeignKeyField
    FROM TableB;
    
    
    

    If this helps kindly accept the answer thanks much.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.