Help Needed With INSERT Trigger

Nov 1, 2007

Hello,
It is rare that I have a user for Triggers, but I have a special case. In a table named tbl_PaymhistCurrentWeek, I have a column called 'AcctCode'. This column will contain data that will be derived from another column called AcctCodeWithZeros. AcctCodeWithZeros contains an account code with leading zeros. The column AcctCode needs to contain the value in AcctCodeWithZeros, only without the leading zeros.

I tried to set up something in a Derived Column Transformation within SSIS, but I can't use PATINDEX.

Here is the latest version of the Trigger:

*****************
CREATE TRIGGER [dbo].[tr_AcctCode]
ON [dbo].[tbl_PaymhistCurrentWeek]
FOR INSERT
AS

BEGIN
INSERT tbl_PaymhistCurrentWeek
(AcctCode, Co, AccountNoWithZeros)
SELECT
id.SUBSTRING([AccountNoWithZeros], PATINDEX('%[^0]%', [AccountNoWithZeros]), 14)AS AcctCode, id.Co, id.AccountNoWithZeros
FROM Inserted id
END
****************
The default for AcctCode is an empty string, which is all I get when I insert into the table. AcctCode will be part of a primary key, so I don't think I can set up AcctCode to be a calculated column. What am I doing wrong?

The DDL for the table is as follows:
tbl_PaymhistCurrentWeek
( AcctCode varchar(10) Default ' ' Not Null,
Co char(2) Not Null,
AcctCodeWithZeros varchar(20) Null
CONSTRAINT (PK_PaymhistCurrentWeek) Primary Key Clustered
(AcctCode, Co)
)


Thank you for your help!

cdun2

View 8 Replies


ADVERTISEMENT

Help Needed With Trigger

Feb 17, 2006

Hi All,

I have this trigger wich runs good!

CREATE trigger trUpdateGEOData
on dbo.BK_Machine
after insert, update
as
updateBK_Machine
setBK_Machine.LOC_Street = GEO_Postcode.STraatID,
BK_Machine.Loc_City = GEO_Postcode.PlaatsID
fromBK_Machine
inner join GEO_Postcode on BK_Machine.loc_postalcode = GEO_Postcode.postcode
and BK_Machine.LOC_Doornumber >= GEO_Postcode.van
and BK_Machine.LOC_Doornumber <= GEO_Postcode.tem
inner join inserted on BK_Machine.MachineID = Inserted.MachineID


Now the thing is that a machine not neccesarily needs a location which mean that if postalcode or doornumber is NULL this trigger should clear the street and city columns.

Does someone have an Idea?

Cheers Wim

View 1 Replies View Related

Trigger Needed

Dec 3, 2007

I'm new to sql server (2000)
and I have to make some trigger before it will be too late :(
I don't have much time to learn it right now. but I'll defiantly do this some time.

I have 2 tables. tbl_A and tbl_B . in tbl_A I have a field named 'money'
and another field 'name' .I need to make a trigger that will run whenever the money field updated.
the update should be like that:
10% of the money that are in the update statement goes to every row in tbl_A where name='<name that used in update query>'. in addition, the 10% and the name goes to tbl_B

View 3 Replies View Related

Code Needed For A Trigger

Mar 11, 2005

Does anyone have code for a trigger that when the user deletes the record trigger it to insert into another table? Thanks in advance and appreciate your help!

View 4 Replies View Related

Login Needed To Bypass A Trigger --- Help

Feb 3, 2000

Is it possible to have a login that can access a table, which has an Update trigger on a column, and do some updating on another column but not have the trigger fire?

I cannot disable the Trigger. This db is on production and the trigger cannot be taken off. I also cannot bcp the data out and do the updating and bcp back in. The production table must remain as is, however I need to update some cols without the trigger firing.

Any ideas??

Thank you,
tw

View 2 Replies View Related

Trigger/Stored Proc Help Needed

Nov 29, 2007

I am fairly new to using triggers and stored procs in SQL Server and could use some help.

Scenario:

I have a table on SQL Server database running on a Windows server (of course) that contains information about articles. A second server in the shop is set up as a LAMP (Linux, Apache, MySQL, PHP) box. What I would like to do is any time the SQL server table is updated or a record is added, tables in MySQL would then be updated to reflect the changes on the first server. My thought is to try and do this with triggers and a stored proc.

Questions:
1) Assuming MySQL can be accessed through ODBC, can an ODBC connection be set up inside a stored proc or trigger, or would this have to be done through the Windows ODBC Data Sources tool in the control panel?

2) Can a Stored Proc be used in a trigger?

3) Can a Stored Proc call an outside function, such as an API call for third party software?

Thanks in advance.

View 1 Replies View Related

Urgent Help Needed - Creating A Trigger?

Feb 16, 2007

I want a stored procedure to run everytime the batch Status field is set to 'Released'


<Code>
CREATE TRIGGER [CSITSS].[tdecker].[FB401BV_TRIGGER] ON [CSITSS].[dbo].[Fbbatch] FOR UPDATE [Status]

AS


DECLARE @RC int
DECLARE @Batch int

SET @Batch = (??? BATCH NUMBER THAT WAS SET TO RELEASE ???)

EXEC @RC = [CSITSS].[tdecker].[GLP_FB401BV_BATCH] @Batch

</Code>

View 9 Replies View Related

Trigger - Require Help For Updating A Trigger Following An INSERT On Another Table

Oct 30, 2007

Table 1





First_Name

Middle_Name

Surname


John

Ian

Lennon


Mike

Buffalo

Tyson


Tom

Finney

Jones

Table 2




ID

F

M

S

DOB


1

Athony

Harold

Wilson

24/4/67


2

Margaret

Betty

Thathcer

1/1/1808


3

John

Ian

Lennon

2/2/1979


4

Mike

Buffalo

Tyson

3/4/04


5

Tom

Finney

Jones

1/1/2000


I want to be able to create a trigger that updates table 2 when a row is inserted into table 1. However I€™m not sure how to increment the ID in table 2 or to update only the row that has been inserted.

View 17 Replies View Related

Trigger - Require Help For Updating A Trigger Following An INSERT On Another Table

Feb 5, 2008

A





ID

Name


1

Joe


2

Fred


3

Ian


4

Bill


B





ID


1


4

I want to be able to create a trigger so that when a row is inserted into table A by a specific user then the ID will appear in table B. Is it possible to find out the login id of the user inserting a row?

I believe the trigger should look something like this:

create trigger test_trigger
on a
for insert
as
insert into b(ID)

select i.id
from inserted i
where
--specific USER

View 9 Replies View Related

Help Needed For Identifying DML Trigger Event Type

Jun 19, 2008

Hi,

I have a query regarding DML Triggers.

I have created a trigger ON a table AFTER Insert, Update staement. In the trigger's body I am making a call to a stored procedure. In the procedure, I want to know the Trigger invoked due to which event : insert or Update as I have to handle bith the cases differently.
But I am not able to find out any SQL server function or property which can distinguish between INSERT and Update events of a trigger.

Waiting for the needful.

View 4 Replies View Related

Help Needed For Identifying DML Trigger Event Type

Jun 19, 2008

Hi,

I have a query regarding DML Triggers.

I have created a trigger ON a table AFTER Insert, Update staement. In the trigger's body I am making a call to a stored procedure. In the procedure, I want to know the Trigger invoked due to which event : insert or Update as I have to handle bith the cases differently.
But I am not able to find out any SQL server function or property which can distinguish between INSERT and Update events of a trigger.

Waiting for the needful.

View 2 Replies View Related

Interaction Between Instead Of Insert Trigger And Output Clause Of Insert Statement

Jan 14, 2008


This problem is being seen on SQL 2005 SP2 + cumulative update 4

I am currently successfully using the output clause of an insert statement to return the identity values for inserted rows into a table variable

I now need to add an "instead of insert" trigger to the table that is the subject of the insert.

As soon as I add the "instead of insert" trigger, the output clause on the insert statement does not return any data - although the insert completes successfully. As a result I am not able to obtain the identities of the inserted rows

Note that @@identity would return the correct value in the test repro below - but this is not a viable option as the table in question will be merge replicated and @@identity will return the identity value of a replication metadata table rather than the identity of the row inserted into my_table

Note also that in the test repro, the "instead of insert" trigger actually does nothing apart from the default insert, but the real world trigger has additional code.

To run the repro below - select each of the sections below in turn and execute them
1) Create the table
2) Create the trigger
3) Do the insert - note that table variable contains a row with column value zero - it should contain the @@identity value
4) Drop the trigger
5) Re-run the insert from 3) - note that table variable is now correctly populated with the @@identity value in the row

I need the behaviour to be correct when the trigger is present

Any thoughts would be much appreciated

aero1


/************************************************
1) - Create the table
************************************************/
CREATE TABLE [dbo].[my_table](
[my_table_id] [bigint] IDENTITY(1,1) NOT NULL,
[forename] [varchar](100) NULL,
[surname] [varchar](50) NULL,
CONSTRAINT [pk_my_table] PRIMARY KEY NONCLUSTERED
(
[my_table_id] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, FILLFACTOR = 70) ON [PRIMARY]
)

GO
/************************************************
2) - Create the trigger
************************************************/
CREATE TRIGGER [dbo].[trig_my_table__instead_insert] ON [dbo].[my_table]
INSTEAD OF INSERT
AS
BEGIN

INSERT INTO my_table
(
forename,
surname)
SELECT
forename,
surname
FROM inserted

END

/************************************************
3) - Do the insert
************************************************/

DECLARE @my_insert TABLE( my_table_id bigint )

declare @forename VARCHAR(100)
declare @surname VARCHAR(50)

set @forename = N'john'
set @surname = N'smith'

INSERT INTO my_table (
forename
, surname
)
OUTPUT inserted.my_table_id INTO @my_insert
VALUES( @forename
, @surname
)

select @@identity -- expect this value in @my_insert table
select * from @my_insert -- OK value without trigger - zero with trigger

/************************************************
4) - Drop the trigger
************************************************/

drop trigger [dbo].[trig_my_table__instead_insert]
go

/************************************************
5) - Re-run insert from 3)
************************************************/
-- @my_insert now contains row expected with identity of inserted row
-- i.e. OK

View 5 Replies View Related

Multiple Insert Call For A Table Having Insert Trigger

Mar 1, 2004

Hi

I am trying to use multiple insert for a table T1 to add multiple rows.

Ti has trigger for insert to add or update multiple rows in Table T2.

When I provide multiple insert SQL then only first insert works while rest insert statements does not work

Anybody have any idea about why only one insert works for T1

Thanks

View 10 Replies View Related

Help Needed With Insert Statement

Nov 13, 2007

Hi,
  I am trying to insert the follows rows to my production database... and this the sample data
  Row Plan PART_ID FUND_ID TOT_ACT1 TOT_ACT2
Number Num
1170925 129602759 19765P471 BB4928.47 CT0.00 DV26.30 GL153.75 TF0.00 WD0.00 OT0.00 EB5108.52 205.0110 24.04 206.0720 24.79
2170925 129602759 35472P406 BB2663.64 CT325.00 DV87.46 GL26.42 TF530.92 WD0.00 OT0.00 EB3633.44 189.0450 14.09 254.6210 14.27
3170925 129602759 LOAN BB1506.88 CT0.00 DV25.48 GL0.00 TF-530.92 WD0.00 OT0.00 EB1001.44 1506.88 1.00 1001.44 1.00
4170925 148603737 19765L587 BB25.14 CT0.00 DV0.46 GL-0.45 TF0.00 WD0.00 OT0.00 EB25.15 5.3830 4.67 5.4790 4.59
5170925 148603737 19765P471 BB7.48 CT0.00 DV0.05 GL0.23 TF0.00 WD0.00 OT0.00 EB7.76 0.3110 24.04 0.3130 24.79
6170925 148603737 35472P208 BB12.53 CT0.00 DV0.28 GL0.09 TF0.00 WD0.00 OT0.00 EB12.90 0.9360 13.39 0.9570 13.48
7170925 148603737 35472P604 BB7.48 CT0.00 DV0.24 GL0.15 TF0.00 WD0.00 OT0.00 EB7.87 0.4720 15.85 0.4870 16.16
8170925 148603737 315805549 BB29.72 CT0.00 DV0.00 GL2.15 TF0.00 WD0.00 OT0.00 EB31.87 1.5320 19.40 1.5320 20.80
9170925 148603737 197199102 BB5.00 CT0.00 DV0.06 GL0.27 TF0.00 WD0.00 OT0.00 EB5.33 0.1650 30.32 0.1670 31.94
 So the number of rows in this table is 1007 right now my insert query inserts all the data but excepts LOAN  and i want Loans inserted in a seperate column in my production dataabse but thats not happening so can some one pls take a look at this query and see whats wrong... My query is as follows1 INSERT INTO Statements..ParticipantPlanFundBalances1
2 (
3 PlanId,
4 ParticipantId,
5 PeriodId,
6 FundId,
7 Loans,
8 --PortfolioId,
9 Act1,
10 TotAct1,
11 Act2,
12 TotAct2,
13 Act3,
14 TotAct3,
15 Act4,
16 TotAct4,
17 Act5,
18 TotAct5,
19 Act6,
20 TotAct6,
21 Act7,
22 TotAct7,
23 Act8,
24 TotAct8,
25 Act9,
26 TotAct9,
27 Act10,
28 TotAct10,
29 Act11,
30 TotAct11,
31 Act12,
32 TotAct12,
33 Act13,
34 TotAct13,
35 Act14,
36 TotAct14,
37 Act15,
38 TotAct15,
39 Act16,
40 TotAct16,
41 Act17,
42 TotAct17,
43 Act18,
44 TotAct18,
45 Act19,
46 TotAct19,
47 Act20,
48 TotAct20,
49 OpeningUnits,
50 OPricePerUnit,
51 ClosingUnits,
52 CPricePerUnit,
53 AllocationPercent
54 )
55 SELECT
56 cp.PlanId,
57 p.ParticipantId,
58 @PeriodId,
59 Case When a.FUND_ID <> 'LOAN' Then f.FundId ELSE 0 END,
60 CASE When a.FUND_ID = 'LOAN' Then 'LOAN' END as Loanfunds,
61 --planinfo.PortfolioId,
62 Case WHEN a.ACT_ID1 = 'BB' Then 1 END,
63 a.TOT_ACT1,
64 Case WHEN a.ACT_ID2 = 'CT'Then 2 END,
65 a.TOT_ACT2,
66 CASE When a.ACT_ID3 = 'DV' then 3 END,
67 a.TOT_ACT3,
68 CASE When a.ACT_ID4 = 'GL' Then 4 End,
69 a.TOT_ACT4,
70 CAse When a.ACT_ID5 = 'TF' THEN 5 END,
71 a.TOT_ACT5,
72 CASE When a.ACT_ID6 = 'WD' THEN 6 END,
73 a.TOT_ACT6,
74 CASE WHEN a.ACT_ID7 = 'OT' THEN 7 END,
75 a.TOT_ACT7,
76 CASE When a.ACT_ID8 = 'EB' THEN 8 END,
77 a.TOT_ACT8,
78 a.ACT_ID9,
79 a.TOT_ACT9,
80 a.ACT_ID10,
81 a.TOT_ACT10,
82 a.ACT_ID11,
83 a.TOT_ACT11,
84 a.ACT_ID12,
85 a.TOT_ACT12,
86 a.ACT_ID13,
87 a.TOT_ACT13,
88 a.ACT_ID14,
89 a.TOT_ACT14,
90 a.ACT_ID15,
91 a.TOT_ACT15,
92 a.ACT_ID16,
93 a.TOT_ACT16,
94 a.ACT_ID17,
95 a.TOT_ACT17,
96 a.ACT_ID18,
97 a.TOT_ACT18,
98 a.ACT_ID19,
99 a.TOT_ACT19,
100 a.ACT_ID20,
101 a.TOT_ACT20,
102 a.UNIT_OP,
103 a.PRICE_OP,
104 a.UNIT_CL,
105 a.PRICE_CL,
106 IsNull(i.ALLOC_PER1,'0.00')
107 FROM
108 ASDBF a
109
110 --Derive the unique Plan Id
111 INNER JOIN Statements..ClientPlan cp
112 ONa.PLAN_NUM = cp.ClientPlanId
113 AND
114 cp.ClientId = @ClientId
115 --Derive the unique ParticipantId from the Participant table
116 INNER JOIN Statements..Participant p
117 ONa.PART_ID = p.PartId
118 -- Derive the unique fund id from the Fund Table
119 INNER JOIN Statements..Fund f
120 ONa.FUND_ID = f.Cusip
121 OR
122 a.FUND_ID = f.Ticker
123 OR
124 a.FUND_ID = f.ClientFundId
125 Left Outer JOIN INVSRC i
126 ONa.FUND_ID = i.INV_ID
127 AND
128 a.PLAN_NUM = i.Plan_Number
129 AND
130 a.PART_ID = i.PART_ID
131 --Get the unique portfolio name ffor the PArticipant Funds..
132 WHERE
133 --Ignore rows that failed the scrub.
134 a.Import = 1
135 AND
136 --Import only those that are not already in the ParticipantPlanFundBalances table
137 NOT EXISTS (
138 SELECT *
139 FROM
140 Statements..ParticipantPlanFundBalances1 pfb
141 WHERE
142 pfb.PlanId = cp.PlanId
143 AND
144 pfb.ParticipantId = p.ParticipantId
145 AND
146 pfb.PeriodId = @PeriodId
147 AND
148 pfb.FundId = f.FundId
149 )

 
 
any help is appreciated.
Regards
Karen

View 7 Replies View Related

(urgent) Help Needed For This Insert Statement

Nov 6, 2007

Hi,
   I am trying to insert the Source name and clientId to a table called clientSource...
 
The User will send in some Dbf File.... So in a particular file called PlanDbf.. I have the following fields
PlanNumber, Name,                   SRC1Name,           SRC2Name,                       SRC3Name....      SRC20Name
170234         Constructions         Employee Deferral   Employer Discretionary      Employer Matching....
 
And in another table called SourceDBF i have the following fields with data
PlanNumber             PARTID   SOURCE_NUM    etc...
170234              123456789         1
170234              123456789         3
170234              451231334         1
So how do i match the Source_NUM with SRCnames when i insert it into the table..
INSERT INTO Statement..ClientSource(@ClientId,                SourceName)SELECT                   s.SOURCE_NUM FROM SourceDBF ..
 but i am stuck..
any help will be appreciated.
Regards
Karen

View 7 Replies View Related

Script Needed To Insert Data To A Different Dbase

Oct 12, 2000

Hello,

I need a sql server 7 script that will migrate data from
my DEV dbase to my WEB dbase. The data desired is for the field
rig_id for rig number 0018. The shell of both dbases are similar.
The table is called rig. An snapshot is below:

DBASE name - DEV

TABLE name - rig

customer rig_id amount
Williams 0011 328
Borsha 0013 256
Kaila 0018 411
Yoida 0021 347

The rig table also exists on the WEB dbase. However, the Kaila data
for rig_id number 0018 needs to be added to the WEB dbase's rig table.
The Williams, Borsha, and Yoida data already exists on both tables.

I need to perform this migration w/ a TRANSACT-SQL stored procedure.

Thanks Very Much IN Advance,

Dave
gunnardl@yahoo.om

View 1 Replies View Related

Insert Trigger For Bulk Insert

Nov 25, 2006

In case of a bulk insert, the “FOR INSERT� trigger fires for each recod or only once?
Thanks,

View 1 Replies View Related

Urgent Help Needed: How To INSERT Into A Field Having UniqueIdentifier Data Type

Jan 8, 2008

I am new at ASP.net and I am having problems inserting data using C# in ASP.netI have created a table named "Profile" in the MS sql server database named "MyDataBase". There is a field named "ID" that has data type 'uniqueidentifier'.I am confused how to INSERT data into this data field. I have used MS Access and MYSQL in which there is an option of auto increment so we don't a unique identifier for each record.Please tell me what can I do to  If I want to have a uniqueidentifier for each new record I INSERT in the "Profile" table of MS sql server database.While trying to insert, I get following errorsCannot insert the value NULL into column 'ID'and I don't know how I can insert something in this field that is of value type unique identifier.Please help me I will be very thankfull of you.

View 5 Replies View Related

Insert Trigger - How To

Nov 20, 2006

 I would like to have the value of a field to be set the return value of
System.Web.Security.Membership.GeneratePassword(12,4)
every time a a row is inserted.
Can you guide with this?
Do you have  some similar sample code?
Thank you very much

View 1 Replies View Related

Insert Trigger

Dec 3, 2006

I would like to have the value of a field to be set the return value of
System.Web.Security.Membership.GeneratePassword(12,4)
every time a a row is inserted.
Can you guide with this?
Do you have  some similar sample code?
Thank you very much

View 1 Replies View Related

Insert Trigger

Nov 12, 2001

Should a insert trigger fire my update trigger as well? it fires it automatically after the insert? Is this a bug?

View 1 Replies View Related

Insert Trigger (Help)

Aug 31, 2000

I have to create a insert trigger that calls a stored procedure usp_a
I need to pass two parameters to this stored procedure, value coming from the row inserted...
What is the syntax? Any help will be appreciated?

View 1 Replies View Related

Insert Trigger Help

Jan 14, 2005

Hi.

Replication is not an option for me so I am trying to creat a trigger that will basically copy any new record to another database. I am using an on insert trigger and I get all records from the table inserted to the new db not just the new record.

Any ideas?

Thanks.

Bill

View 4 Replies View Related

Pre-insert Trigger

Apr 26, 1999

I am trying to write a pre-insert trigger. I want a row to be deleted first and then have the new row inserted. The end result is an insert/update statement. If anyone knows how to do this or has a better way, let me know, Please.

View 3 Replies View Related

Insert Trigger

Oct 13, 1998

I am trying to write an insert trigger for the following problem. I have a table that contains a field (amount) that contains currency amount. Each row could be a record from a transaction in a different country. I would like each record to be converted into U.S. currency as it is inserted. So I created an other table that contains that exchange rate. How can I create a trigger that does this?

Tax Detail Table Exchange Table

Account# int Country char
Description char ExchangeRate Money
Amount money
Country char

I am working with MSS 6.5. Any and all help will be greatly appreciated.

Fidencio Peña

View 3 Replies View Related

ON INSERT TRIGGER

Dec 8, 1998

MSSQL 6.5

Is there any way to change some columns on inserted lines in ON INSERT trigger?

My notice: I try to find something about it in SQLBOOKS, but I found nothing.
It's possibly not TRUEEE!!!!! It wants me to grumble.


Thank for your answer.

View 1 Replies View Related

Trigger INSERT Q

Nov 28, 2005

Really simple question - I have the following trigger for the INSERT event for Tbl_B:

CREATE TRIGGER calc_total ON [dbo].[Tbl_B]
FOR INSERT
AS

DECLARE @VATRate AS decimal(19,2)
SET @VATRate = (
SELECT Val
FROM Tbl_Numeric_Refs
WHERE Ref = 'VATRate'
)

UPDATE Tbl_B
SET [Total] = ((@VATRate / 100) * [PriceA]) + [PriceA],
[VATRate] = @VATRateHow can I restrict the UPDATE within the trigger to the record(s) being INSERTed? Or am I over-complicating things, and should use a simple UDF for this instead?

View 2 Replies View Related

Trigger On Insert

Oct 22, 2007

Is it possible to pick up the value that is being inserted within the scope of a trigger? For example, if I were to run the following

INSERT INTO people (firstname, lastname)
VALUES ('George', 'V')

Would it be possible to access these values in a trigger before they are inserted?

CREATE TRIGGER trigger1
ON people
FOR INSERT
AS
IF EXISTS (SELECT 1 FROM table1 WHERE firstname = <the value being inserted>) BEGIN
Print '1'
END
ELSE BEGIN
Print '2'
END
GO

View 4 Replies View Related

SQL Trigger To Run On Insert Only

Nov 15, 2007

Rightio - this is probably a simple question for you SQL afficionados.I have written a trigger to update a master table with a CreateDate field. Simple enough I thought but it updates this field when the existing record is edited as well - not so good.This is how it looks like:CREATE TRIGGER CreateDateON MasterFOR UPDATE ASDECLARE@idMaster intSELECT @idMaster = idMaster from Insertedupdate Masterset CreatedDate = getdate()where idMaster = @idMasterGOWell I know I can write an IF statement that will basically say if the field is not null then only update - fair enough - but is there a simpler way to do this? Is there a way I need to write my CREATE TRIGGER statement that ONLY makes it run when it is a NEW INSERT ONLY?THANKS!

View 8 Replies View Related

Trigger: Before Insert

Jan 27, 2004

Hi, i'm a newbie in writting trigger and stored procedure, need to get help on this:

I cannnot find anyway to run the trigger before insert, anyway to do this?

Thanks.

View 2 Replies View Related

Trigger INSTEAD OF INSERT??

Mar 2, 2004

So... dear friends
I want to insert values to a table without firing the foreign key Constraint.
I think one way is to insert values into the parent table first and then perform the initial insert.
Is this possible with an INSTEAD OF INSERT Trigger or another way? If yes can you make an example? I want to check for dublicate values in the parent table too!!
Thanx!

View 6 Replies View Related

Trigger For Insert

May 4, 2008

I have an EMPLOYEE table and DEPARTMENT table, i have to create one to many relationship where one employee can be in many departments, please guide me

create table employee (e_id INTEGER, e_fname varchar(30), e_lname varchar(30), d_id INTEGER references department(d_id))

create table department (d_id INTEGER, d_name varchar(30))

but here the problem would be while inserting into employee table since i have no primary key... do i need to use trigger to insert the right values.

View 10 Replies View Related

Insert Trigger

May 18, 2008

I'm having table as below,
StudentEnroll_Thismonth
TransID(AutoNumber) | StudentID | Subject | TransDate
------------------------------------------------
1 | 0021 | A890 | 4/1/2008
2 | 0021 | A830 | 4/1/2008
3 | 0025 | A890 | 4/1/2008
4 | 0025 | A112 | 4/1/2008
5 | 0026 | A545 | 4/1/2008
.............
.............
99 | 0021 | A900 | 4/30/2008
100 | 0021 | A902 | 4/30/2008
101 | 0025 | A900 | 4/30/2008
*The table above contains what subject taken by student

Let's say, GETDATE()=5/1/2008
If execute Trans-SQL below,
INSERT INTO StudentEnroll_ThisMonth(StudentID,Subject,TransDate) values(0023,'B328',GETDATE())

How the trigger looks like to make sure the data in table shown as follow,
StudentEnroll_Thismonth
TransID(AutoNumber) | StudentID | Subject | TransDate
-----------------------------------------------------------
120 | 0023 | B328 | 5/1/2008
*All the previous month record move to StudentEnroll_PreviousMonth automatically

StudentEnroll_PreviousMonth
TransID(AutoNumber) | StudentID | Subject | TransDate
------------------------------------------------
..................
..................
..................
200 | 0021 | A890 | 4/1/2008
201 | 0021 | A830 | 4/1/2008
203 | 0025 | A890 | 4/1/2008
204 | 0025 | A112 | 4/1/2008
205 | 0026 | A545 | 4/1/2008
.................
.................
301 | 0021 | A900 | 4/30/2008
302 | 0021 | A902 | 4/30/2008
303 | 0025 | A900 | 4/30/2008

Anyone can help me to show the trigger?

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved