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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:17:02+00:00 2026-06-03T06:17:02+00:00

In relation Person (SSN, State, Name), add a tuple-based check: if a person’s State

  • 0

In relation Person (SSN, State, Name), add a tuple-based check: if a
person’s State is NY, then the first three digits of his SSN has to be
between ‘050’ and ‘134’. (Hint: use LEFT function in SQL).

CREATE TABLE Person (
    SSN   INT PRIMARY KEY,
    State   CHAR(50),
    Name  CHAR(100),
    CHECK ( 
        SELECT LEFT (SSN, 3) AS FirstThreeDigits, SSN FROM Person,
        WHERE Person.State == ‘NY’) between '050' and between '134'
);

I am not comfortable with the CHECK condition here. I am not sure if this is the right way doing conditional check. Can someone please verify this? If not, how do we do a conditional check?

We need this:

if state == 'NY', perform CHECK

Do we need a trigger? I was thinking that if a new insert / update occurs, check the value. But the question doesn’t ask that.

  • 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-06-03T06:17:04+00:00Added an answer on June 3, 2026 at 6:17 am

    Ok so its generic but DDL typically isn’t but lets use the doc on SQL Server CHECK Constraints as a guide anyway

    You can create a CHECK constraint with any logical (Boolean)
    expression that returns TRUE or FALSE based on the logical operators.
    For the previous example, the logical expression is:
    salary >= 15000 AND salary <= 100000.

    Note that the above example from the docs is not a SELECT statement but and expression. This means all you need to do is come up with a expression that returns TRUE

    when all of the following are true

    1. State is NY
    2. The Left three digits of the SSN is => ‘050’
    3. The Left three digits of the SSN is <= 134.

    Or

    1. Sate is not NY

    Remembering that you can Group a set of logical expressions in a Parens

    e.g.

    (Group of logical expressions) OR (Group of logical expressions)
    

    It shouldn’t be too hard

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

Sidebar

Related Questions

I have three table in SQL database such as table Person has relation one
Given a Relation Person(id,name,momid,dadid) Return all siblings (ie those with common momid,dadid) eg 1,2
in class Person i have relation to class Position, and the class Position has
Table - Person {ID, Name, Age, Line1, City, State, Zip} FD set 1) ID
I have two tables: Person(personID, name, phone, email); Relation(child_personID, parent_playerID); The relationship table helps
I am trying to add a self relation in an existing Innodb table here
I have this class mapped as a entity, lets call it Person. Person has
I have two models: Person and Relation. The second one stores information about relations
@ManagedBean @SessionScoped public class User { private Person person; ... user.hbm.xml <hibernate-mapping> <class name=entry.User
Is is possible to do automatic relation fetching in GORM / Grails? class Person

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.