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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:06:01+00:00 2026-05-19T04:06:01+00:00

Situation is as below. I have a table like here: Col1 Col2 Col3 Col4

  • 0

Situation is as below. I have a table like here:

Col1 Col2 Col3 Col4 Col5 Col6
a    b    c     1   e     1
a    b    c     3   l     1
a    b    c     1   e     0
a    b    f     1   f     1

The idea is that I cant update existing data or add new row
which has combination a b c 1 ? 1.
I have to block adding 1 in last column if there
is already some combination of cols 1-3, but I can still may
add same combination with 0 in col 6.

  • 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-19T04:06:02+00:00Added an answer on May 19, 2026 at 4:06 am

    For more complex logic, you use triggers: trigger gets triggered at specified time (insert, update, delete) – before (use word “for”) or after.

    Your example – trigger that does not allow inserting given combination of columns:

    create table MyTable (
        Col1 char, Col2 char, Col3 char, Col4 int, Col5 char, Col6 int
    );
    
    insert into MyTable (Col1, Col2, Col3, Col4, Col5, Col6)
    values ('a', 'b', 'c', 1, 'e', '1');
    insert into MyTable (Col1, Col2, Col3, Col4, Col5, Col6)
    values ('a', 'b', 'f', 1, 'e', '1');
    
    create trigger [dbo].[trigger_MyTable] on MyTable for insert as
    begin
        if 0 < (select count(*) from inserted where 
            Col1='a' and Col2='b' and Col3='c' and Col4=1 and Col6=1)
        begin
            raiserror 50009 'wrong insert, no way!'
            rollback transaction
            return
        end
    end;
    
    -- now it fails
    insert into MyTable (Col1, Col2, Col3, Col4, Col5, Col6)
    values ('a', 'b', 'c', 1, 'e', '1');
    

    Of course, you can create trigger for update (use “inserted” table), or for delete (use “deleted” table).
    You might do other actions (like inserting another row in another table), …

    Give a MSDN try as well: http://msdn.microsoft.com/en-us/library/ms189799(v=SQL.90).aspx

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

Sidebar

Related Questions

Here's the situation: I would like to iterate through a table with input controls,
My situation looked just like the problem discussed here: Clear float issue That is:
I have a situation where my DB tables are like below, I am wondering
I have what seems like an odd situation here. I'm launching dialogs from a
Situation: I have a simple XML document that contains image information. I need to
The situation: I have a pieceofcrapuous laptop. One of the things that make it
The situation is this: You have a Hibernate context with an object graph that
I have the below situation Case 1: Input : X(P)~AK,X(MV)~AK Replace with: AP Output:
heres the situation. I have a table called as maps coordinates the schema is
I would like some recommendations on the following situation: I have to build a

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.