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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:28:43+00:00 2026-06-01T11:28:43+00:00

Based on Constraint for only one record marked as default would the same approach

  • 0

Based on Constraint for only one record marked as default would the same approach of a view and unique clustered index apply if I wanted to achieve the same result at a table scope?

I have a table called Accounts. There can be only one System account, however there can be many Partner and Client accounts. Each type of account does not vary in terms of the columns but instead with just the Type column.

ID | Type    | Name 
1    System    Contoso
2    Partner   Wingtip
3    Partner   Northwind
4    Client    Adventure Works
5    Client    Fabrikam

In the above I want to prevent adding another System account, but allow many partner and client accounts. It feels like a concern that belongs in the database as opposed to the domain (maybe I’m wrong)?

  • 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-01T11:28:44+00:00Added an answer on June 1, 2026 at 11:28 am

    If you know that the system account will always have ID number 1, you can implement this with a CHECK constraint. Something along these lines . . .

    create table accounts (
      id integer primary key,
      type varchar(15) not null,
      name varchar(15) not null,
      unique (type, name),
      check (
        (id = 1 and type = 'System') or
        (id <> 1 and type <> 'System')
      )
    );
    

    In fact, if this is your database, the system account can have any id number. Just change the CHECK() constraint to match.

    If you’re building for deployment to a client site, you can add the system account before deployment. (And you probably should, regardless of how you handle the constraints.)

    Think about about what to do when a user tries to delete rows from this table. (Especially that system account row.) Then think about what to do when a database admin tries to delete rows from that table.

    You can probably use a foreign key constraint (no cascade) or a trigger to prevent a database admin from accidentally deleting the system account. The admin can probably get around those restrictions, but you’d hope she knows what she’s doing if she’s willing to go that far to delete a row.

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

Sidebar

Related Questions

I want a table which can only have one record. My current solution is:
Based on this , how would you make ignoring parameters more succint? var m
I have two instances of NSScrollView both presenting a view on the same content.
I want Suggestion that which one is better based on performance? List<byte[]> or HashMap<String,byte[]>
I have a simple MySQL table with one column: name . I would like
Is there a way to apply several different csharp generic constraints to the same
I have custom components which must adjust their text content based on space constraints.
based on .designer.cs, i infer that the menu's arrangement is based on the order
Based on some answers to this question it appears that +alloc does some behind-the-scenes
Based on feedback I got from this question , I'm interested in using Lazy

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.