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
 Transact-SQL (2000)
 Trigger INSERT

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-07-10 : 08:51:16
DIJE writes "I have a Table :
Create Table tblCat
( CatID Int,
CatName Varchar(30) Null,
Constraint PK_tblCat Primary Key (CatID)
)

When i Insert Into tblCat :
INSERT INTO tblCat(CatName) Values ('CategoryName')

I want to Update My New CatID Value base of Max(tblCat.CatID), and i want to do this in INSERT TRIGGER :


any help will be greats."

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-07-10 : 09:44:07
First, you can't create a Primary Key constraint on a nullable column, so you DDL will not comple.

Second, you will have to use an INSTEAD OF trigger (new in SQL2K). A TRIGGER for INSERT will execute after the DML (insert statement) has been run and the error has been generated (thus halting processing of the batch).

Third, have you considered an IDENTITY property on the CatID column?

<O>
Go to Top of Page
   

- Advertisement -