Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Sample of BOL doesnt Work ?

Author  Topic 

CLages
Posting Yak Master

116 Posts

Posted - 2005-10-19 : 16:48:47
hi, where is my mistake

if i run this taken from BOL, @@error return 547

USE pubs
GO

UPDATE authors
SET au_id = '172 32 1176'
WHERE au_id = '172-32-1176'
IF @@ERROR = 547
print 'I got a Error'


But if i change au_id to a Invalid key
i get no Erros in @@error
@@error return 0

does any body knows why?
tks

C. Lages

USE pubs
GO

UPDATE authors
SET au_id = '172 32 1176'
WHERE au_id = 'xxx-32-1176'
IF @@ERROR = 547
print 'I got a Error'







nathans
Aged Yak Warrior

938 Posts

Posted - 2005-10-19 : 16:53:19
Because you didnt update anything.

select count(*) from authors where au_id = '172-32-1176'
select count(*) from authors where au_id = 'xxx-32-1176'

Nathan Skerl
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-10-19 : 16:53:48
Because no rows are updated for : 'xxx-32-1176'
Thus no foreign key violation (547) occurs.

Go to Top of Page
   

- Advertisement -