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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:10:12+00:00 2026-05-31T05:10:12+00:00

Is it possible on Sybase to define a constraint(s) which require a column to

  • 0

Is it possible on Sybase to define a constraint(s) which require a column to be a foreign key and also satisfy a condition based on the value of a foreign column, e.g. in the below example tables could a constraint be created on the “product” table such that “product.code is a foreign key of a brand.code which has valid=1”?

CREATE TABLE brand (
    code        char(8)       NOT NULL,
    valid       int           NOT NULL,
    rowid       numeric(10,0) IDENTITY,
    CONSTRAINT brand_pk PRIMARY KEY (code),
    CONSTRAINT valid_check CHECK (valid IN (0,1))
)

CREATE TABLE product (
    code        char(8)       NOT NULL,
    CONSTRAINT product_pk PRIMARY KEY (code)
)
  • 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-31T05:10:12+00:00Added an answer on May 31, 2026 at 5:10 am

    I think it’s best to change the structure just a little bit.

    CREATE TABLE brand (
        code        char(8)       NOT NULL,
        valid       int           NOT NULL,
        rowid       numeric(10,0) IDENTITY,
        CONSTRAINT brand_pk PRIMARY KEY (code),
    
        -- The following UNIQUE constraint lets the pair of values be the target of 
        -- a foreign key reference.
        CONSTRAINT brand_is_valid UNIQUE (code, valid),
    
        CONSTRAINT valid_check CHECK (valid IN (0,1))
    );
    
    CREATE TABLE product (
        code        char(8)       NOT NULL,
        valid       int           NOT NULL,
    
        -- The column "code" is a PK in the referenced table, so this still works. It's 
        -- a 1:0 or 1:1 relationship.
        CONSTRAINT product_pk PRIMARY KEY (code),
    
        -- The next constraint requires a unique constraint on the pair of 
        -- columns in the table "brand".  By itself, it references every row
        -- in "brand". That's too many rows.
        CONSTRAINT product_fk FOREIGN KEY (code, valid) 
                              REFERENCES brand (code, valid),
    
        -- But this constraint restricts the foreign key references to only those 
        -- rows that have valid = 1 in the table "brand".
        CHECK (valid = 1)
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Sybase, is it possible to create a a foreign key from a table
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Is it possible to link tables from other databases (MS SQL, Sybase, etc.) inside
Possible Duplicate: array_splice() for associative arrays How to add an array value to the
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Is it possible to convert varchar to hex and vice-versa using Sybase ASE?
I've a Microsoft and Sybase stored procedures that return result as return @value. I
Is it possible to mock Sybase DB connection in jTDS? I'd like to do
Possible Duplicate: Python urllib2 Progress Hook I have a script which uploads a file
Is it possible to create indices on views in Sybase (> ASE 12.5)?

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.