|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
|
|
#1
|
|||
|
|||
|
triggers in "insert" statement
ok
i am absolute newbe if it comes to ms sql server, so here's the problem : i have a stored procedure that inserts a new row into a table. now - i'd like to have a trigger that would give each new row a succesive id number. for example if i have : id_num title number_of_copies --------------------------------- 123 "ghost" 1232 after an insert operation, i'd like to have : id_num title number_of_copies --------------------------------- 123 "ghost" 16 124 "shrek" 19 another problem is calling this procedure and number of arguments it needs. when i call it, i dont want to insert an id_num there. i just need to give it the title and num of copies. in case of FIREBIRD, it's easy - i just call a trigger initiation from a stored procedure. how do i do this in mssql server? all help will be appreciated. cheers
__________________
ania Last edited by aniaahh : May 23rd, 2004 at 09:38 AM. Reason: wrong title |
|
#2
|
|||
|
|||
|
Define an identity attribute for the column when creating the table. You don't need a trigger.
|
|
#3
|
|||
|
|||
|
well i'll try to read sth about it
but just for the future : how do i use triggers in stored procedures? i mean - how do i let the procedure know, that for example the value i'll insert to the table will come from the trigger? |
|
#4
|
||||
|
||||
|
Quote:
You don't. Quote:
You can replace an inserted value within the trigger by doing an update on the trigger table or by using an instead of trigger. |
|
#5
|
|||
|
|||
|
ok
my id column now has an identity attribute. suppose i want to insert new data into the table. should i just skip the id number when passing the values? should i pass anything and it would be ignored anyway? what is the way of dealing with it? |
|
#6
|
|||
|
|||
|
Omit the column with the identity attribute from the insert statement.
Code:
create table ogrish(
aleb varchar(10),
bleb varchar(10),
cleb int,
perQuem int identity(100,1),
primary key (perQeum))
--
insert into ogrish(aleb,bleb,cleb) values('x','y',4711)
|
|
#7
|
|||
|
|||
|
thanks very much for your help
![]() |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > triggers in "insert" statement |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|