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 883425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:35:12+00:00 2026-05-15T12:35:12+00:00

I want a column from a table to have a limited domain, which is

  • 0

I want a column from a table to have a limited domain, which is listed in a different table. Usually, I’d just do this:

ALTER TABLE Table1
ADD CONSTRAINT FK_Especialidade FOREIGN KEY (column1)
REFERENCES Table2

However the values that “column1” must reference should not be a Primary Key in Table2. Any suggestions?

  • 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-15T12:35:13+00:00Added an answer on May 15, 2026 at 12:35 pm

    You could use a trigger (this is off the top of my head, the syntax might not be right…)

    CREATE TRIGGER MyTrigger ON Table1 FOR INSERT, UPDATE
    AS
      IF UPDATE(column1)
      BEGIN
        IF NOT EXIST (SELECT column2 FROM Table2 WHERE column2 = column1)
          RAISERROR ('Invalid column1 value.', 16, 1)
        END
      END
    

    Make sure you at least have an index on column2 in Table2, you want your triggers to execute as fast as possible!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want ActiveRecord to lookup by a non-id column from a table. Hope this
I have a view like this: CREATE VIEW MyView AS SELECT Column FROM Table
I want to select rows from a table if a column contains a certain
I want to display the column 'name' after being found from the table mytest.
If I want to see which values from an Excel spreadsheet column don't match
i want to know how to get all column value from table using sphinx
I have a query in MS Access which creates a table from two subqueries.
Hello i want to show data from table where i have to show only
I have a table with this kind of data in one of its column:
I'm trying do something like this: SELECT * FROM table WHERE column IN (1,2,3)

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.