MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old May 23rd, 2004, 09:37 AM
aniaahh aniaahh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: poland
Posts: 88 aniaahh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 39 sec
Reputation Power: 5
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

Reply With Quote
  #2  
Old May 23rd, 2004, 10:35 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,745 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 20 h 25 m 5 sec
Reputation Power: 31
Define an identity attribute for the column when creating the table. You don't need a trigger.

Reply With Quote
  #3  
Old May 23rd, 2004, 10:49 AM
aniaahh aniaahh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: poland
Posts: 88 aniaahh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 39 sec
Reputation Power: 5
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?

Reply With Quote
  #4  
Old May 23rd, 2004, 11:35 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,745 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 20 h 25 m 5 sec
Reputation Power: 31
Quote:
how do i use triggers in stored procedures?


You don't.

Quote:
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?


You can replace an inserted value within the trigger by doing an update on the trigger table or by using an instead of trigger.

Reply With Quote
  #5  
Old May 23rd, 2004, 02:47 PM
aniaahh aniaahh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: poland
Posts: 88 aniaahh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 39 sec
Reputation Power: 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?

Reply With Quote
  #6  
Old May 24th, 2004, 01:32 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,745 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 20 h 25 m 5 sec
Reputation Power: 31
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)

Reply With Quote
  #7  
Old May 24th, 2004, 01:49 AM
aniaahh aniaahh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: poland
Posts: 88 aniaahh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 39 sec
Reputation Power: 5
thanks very much for your help

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > triggers in "insert" statement


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway