Professional Web Applications Themes

Triggers and importing data - Microsoft SQL / MS SQL Server

Hi again;) I have a table with columns ID, A and B. There is a trigger for update and insert, which modifies column B when A is changed (i use IF UPDATE(A)). When I import from a table in Access (containg only columns ID and A), after whole operation column B remain unchanged. Anybody knows why? Of course, trigger doesn't work when I manually add records to the table. So the promblem is not in importing data. CREATE TRIGGER MyTrigger ON [dbo].[Table] FOR INSERT, UPDATE AS IF UPDATE(A) BEGIN UPDATE Table SET B = A + 1 FROM inserted WHERE ...

  1. #1

    Default Triggers and importing data

    Hi again;)
    I have a table with columns ID, A and B. There is a trigger for
    update and insert, which modifies column B when A is
    changed (i use IF UPDATE(A)).
    When I import from a table in Access (containg only
    columns ID and A), after whole operation column B remain
    unchanged. Anybody knows why? Of course, trigger doesn't
    work when I manually add records to the table. So the
    promblem is not in importing data.

    CREATE TRIGGER MyTrigger ON [dbo].[Table]
    FOR INSERT, UPDATE
    AS
    IF UPDATE(A)
    BEGIN
    UPDATE Table
    SET B = A + 1
    FROM inserted
    WHERE Table.ID = inserted.ID
    END

    Thanks!
    Przemo
    Przemo Guest

  2. #2

    Default Re: Triggers and importing data

    This should work, whats the problem.
    try this:
    (if you are using table name as "table", avoid it)

    create table [table] (id int,a int, b int)

    CREATE TRIGGER MyTrigger ON [dbo].[Table]
    FOR INSERT, UPDATE
    AS
    IF UPDATE(A)
    BEGIN
    UPDATE [Table]
    SET [table].B = [table].A + 1
    FROM inserted
    WHERE [Table].ID = inserted.ID
    END

    insert into [table](id,a) values(1,2)

    update [table] set a=4

    --
    --Vishal

    "Przemo" <p.dutkiewiczdeltatrans.pl> wrote in message
    news:011501c34316$07629ab0$a101280aphx.gbl...
    > Hi again;)
    > I have a table with columns ID, A and B. There is a trigger for
    > update and insert, which modifies column B when A is
    > changed (i use IF UPDATE(A)).
    > When I import from a table in Access (containg only
    > columns ID and A), after whole operation column B remain
    > unchanged. Anybody knows why? Of course, trigger doesn't
    > work when I manually add records to the table. So the
    > promblem is not in importing data.
    >
    > CREATE TRIGGER MyTrigger ON [dbo].[Table]
    > FOR INSERT, UPDATE
    > AS
    > IF UPDATE(A)
    > BEGIN
    > UPDATE Table
    > SET B = A + 1
    > FROM inserted
    > WHERE Table.ID = inserted.ID
    > END
    >
    > Thanks!
    > Przemo

    Vishal Parkar Guest

  3. #3

    Default Re: Triggers and importing data

    Thanks,

    but I have forgotten to mention one thing.
    My trigger works for update but not for insert. So whats
    the problem?
    TABLE it's not name for my table. It is only example.

    Przemo
    Przemo Guest

  4. #4

    Default Triggers and importing data

    Dear Przemo,

    Iam not sure, but try working out like this..

    Declare a variable in your trigger, store the value of A
    from inserted table in this local variable.

    Use this local variable in the update statement.

    Also try the same for your ID variable used in the wheer
    clause..

    HTH

    Bunty
    >-----Original Message-----
    >Hi again;)
    >I have a table with columns ID, A and B. There is a
    trigger for
    >update and insert, which modifies column B when A is
    >changed (i use IF UPDATE(A)).
    >When I import from a table in Access (containg only
    >columns ID and A), after whole operation column B remain
    >unchanged. Anybody knows why? Of course, trigger doesn't
    >work when I manually add records to the table. So the
    >promblem is not in importing data.
    >
    >CREATE TRIGGER MyTrigger ON [dbo].[Table]
    >FOR INSERT, UPDATE
    >AS
    >IF UPDATE(A)
    >BEGIN
    >UPDATE Table
    >SET B = A + 1
    >FROM inserted
    >WHERE Table.ID = inserted.ID
    >END
    >
    >Thanks!
    >Przemo
    >.
    >
    Bunty Parekh Guest

  5. #5

    Default Re: Triggers and importing data

    Hi

    Be wary of this technique as inserted may contain more than one row.

    I think Przemo has solved his problem, judging by the subsequent posts.

    John


    "Bunty Parekh" <Bunty_dphotmail.com> wrote in message
    news:6b6301c343bc$d20dd3a0$a401280aphx.gbl...
    > Dear Przemo,
    >
    > Iam not sure, but try working out like this..
    >
    > Declare a variable in your trigger, store the value of A
    > from inserted table in this local variable.
    >
    > Use this local variable in the update statement.
    >
    > Also try the same for your ID variable used in the wheer
    > clause..
    >
    > HTH
    >
    > Bunty
    >
    > >-----Original Message-----
    > >Hi again;)
    > >I have a table with columns ID, A and B. There is a
    > trigger for
    > >update and insert, which modifies column B when A is
    > >changed (i use IF UPDATE(A)).
    > >When I import from a table in Access (containg only
    > >columns ID and A), after whole operation column B remain
    > >unchanged. Anybody knows why? Of course, trigger doesn't
    > >work when I manually add records to the table. So the
    > >promblem is not in importing data.
    > >
    > >CREATE TRIGGER MyTrigger ON [dbo].[Table]
    > >FOR INSERT, UPDATE
    > >AS
    > >IF UPDATE(A)
    > >BEGIN
    > >UPDATE Table
    > >SET B = A + 1
    > >FROM inserted
    > >WHERE Table.ID = inserted.ID
    > >END
    > >
    > >Thanks!
    > >Przemo
    > >.
    > >

    John Bell Guest

Similar Threads

  1. Importing data from one to another
    By DataPacks.com in forum Coldfusion Database Access
    Replies: 2
    Last Post: March 26th, 01:14 PM
  2. Importing FDF Data
    By Volker_Kleinschmidt@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 5
    Last Post: May 7th, 03:08 PM
  3. Importing Excel data
    By chris in forum FileMaker
    Replies: 5
    Last Post: August 19th, 01:34 PM
  4. Triggers and importing data once again
    By Przemo in forum Microsoft SQL / MS SQL Server
    Replies: 2
    Last Post: July 6th, 04:53 PM
  5. Importing lots of data
    By SriSamp in forum Microsoft SQL / MS SQL Server
    Replies: 4
    Last Post: June 30th, 02:29 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139