If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > keep an insert from working, if field matches

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-13-11, 09:55
ecourt ecourt is offline
Registered User
 
Join Date: May 2008
Posts: 10
keep an insert from working, if field matches

so I have a sybase 12.5 db, with a table of phone numbers.
If the phone number is blank, or 000 000 0000, I need the insert to fail.

I can't 'fix' it from the front-end, as I have no control over the utility that does the insert.

I know there's a way to do this, but I'm having trouble figuring it out.

Thanks
Reply With Quote
  #2 (permalink)  
Old 01-13-11, 10:00
agrawal.meet agrawal.meet is offline
Registered User
 
Join Date: Jun 2010
Posts: 51
Use insert trigger.
__________________
Please always reply to the post if it was helpful. Others may find it helpful.
Reply With Quote
  #3 (permalink)  
Old 01-13-11, 11:36
ecourt ecourt is offline
Registered User
 
Join Date: May 2008
Posts: 10
thoughts on why this one don't work ?


Code:
create trigger test_phone
    on phone_table
    for insert,update
    as
    if update(phone) in ("0000000000","000","")
    begin
        rollback transaction
    end
Keeps giving a error on IN
Reply With Quote
  #4 (permalink)  
Old 01-14-11, 09:22
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
You probably want something like this
Code:
if update(phone)
  if exists (select 1 from inserted where phone in ("0000000000","000",""))
    rollback transaction
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On