Search Results

Search found 1486 results on 60 pages for 'triggers'.

Page 10/60 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • How to update a single table using trigger in MS SQL 2008

    - by Yakob-Jack
    I have a table PeroidicDeduction and the fields are ID(auto-increment),TotalDeduction(e.g.it can be loan),Paid(on which the deduction for each month),RemainingAmount, What I want is when every time I insert or update the table---RemainingAmount will get the value of TotalDeduction-SUM(Paid)....and writ the following trigger...but dosen't work for me CREATE TRIGGER dbo.UpdatePD ON PeroidicDedcution AFTER INSERT,UPDATE AS BEGIN UPDATE PeroidicDedcution SET REmaininAmoubnt=(SELECT TotalDeduction-(SELECT SUM(Paid) FROM PeroidicDeduction) FROM PeroidicDeduction) END NOTE: it is on a Single table

    Read the article

  • Why am I unable to create a trigger using my SqlCommand?

    - by acidzombie24
    The line cmd.ExecuteNonQuery(); cmd.CommandText CREATE TRIGGER subscription_trig_0 ON subscription AFTER INSERT AS UPDATE user_data SET msg_count=msg_count+1 FROM user_data JOIN INSERTED ON user_data.id = INSERTED.recipient; The exception: Incorrect syntax near the keyword 'TRIGGER'. Then using VS 2010, connected to the very same file (a mdf file) I run the query above and I get a success message. WTF!

    Read the article

  • SQL Trigger dont works...

    - by Gabotron
    Is there a way in which a Trigger is not fired? We have this situation: We have a table and there are rows that are been deleted. We need to know who and/or when these row are deleted. We create this trigger: ALTER TRIGGER [dbo].[AUDITdel_nit] ON [dbo].[Client] FOR DELETE AS Insert into AUDIT select 'Delete', getdate(), 'Row Deleted', SYSTEM_USER, host_name(), (select 'ID Client: ' + convert(varchar(12),Id) from deleted), 'Client' ,APP_NAME() We made somte test: deleting rows vis stored procedures and the deleted rows appears in our AUDIT table. But suddenly today we found a row deleted that dont appears in the AUDIT table... Any idea how it can be done?

    Read the article

  • Use MySQL trigger to update another table when duplicate key found

    - by Jason
    Been scratching my head on this one, hoping one of you kind people and direct me towards solving this problem. I have a mysql table of customers, it contains a lot of data, but for the purpose of this question, we only need to worry about 4 columns 'ID', 'Firstname', 'Lastname', 'Postcode' Problem is, the table contains a lot of duplicated customers. A new table is being created where each customer is unique and for us, we decide a unique customer is based on 'Firstname', 'Lastname' and 'Postcode' However, (this is the important bit) we need to ensure each new "unique" customer record also can be matched to the original multiple entries of that customer in the original table. I believe the best way to do this is to have a third table, that has 'NewUniqueID', 'OldCustomerID'. So we can search this table for 'NewUniqueID' = '123' and it would return multiple 'OldCustomerID' values where appropriate. I am hoping to make this work using a trigger and the on duplicate key syntax. So what would happen is as follows: An query is run taking the old customer table and inserting it in to the new unique table. (A standard Insert Select query) On duplicate key continue adding records, but add one entry in to the third table noting the 'NewUniqueID' that duped along with the 'OldCustomerID' of the record we were trying to insert. Hope this makes sense, my apologies if it isn't clear. I welcome and appreciate any thoughts on this one! Many thanks Jason

    Read the article

  • WPF- Is there a way to stop TreeViewItems from becoming selected and activated when thier parent TreeViewItem is selected?

    - by Justin
    I have a control template for TreeViewItems and instead of showing the normal FocusVisualStyle I have a MultiTrigger set up like this: <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="true"/> <Condition Property="IsSelectionActive" Value="true"/> </MultiTrigger.Conditions> <Setter Property="FontWeight" Value="Bold"/> </MultiTrigger> However this also causes the FontWeight to change to bold when a TreeViewItem's parent item is selected. Is there any way I can stop that from happening?

    Read the article

  • Is it possible to set a parameterized build or pass an environment variable via a hudson build trigger?

    - by Tim
    I'd like to use hudson to trigger a "promotion" of a build. The build would be a simple script that just copies a release candidate installer file from one location to another. (development dir to release/stable dir) Our build server is not on the public internet, but I want to be able to send an email or a text message or an IM with the build number to hudson, which will parse the build number and then do the copy/move. In looking at the jabber/IM plugin it does not look like this is possible (the parameter part) Has anyone solved this in some way? Should I use some other mechanism? I would prefer not to have to do the manual steps each time (SCP/FTP, etc) - I just want any QA team member to be able to trigger the build server to do the promotion.

    Read the article

  • Muti-Schema Privileges for a Table Trigger in an Oracle Database

    - by sisslack
    I'm trying to write a table trigger which queries another table that is outside the schema where the trigger will reside. Is this possible? It seems like I have no problem querying tables in my schema but I get: Error: ORA-00942: table or view does not exist when trying trying to query tables outside my schema. EDIT My apologies for not providing as much information as possible the first time around. I was under the impression this question was more simple. I'm trying create a trigger on a table that changes some fields on a newly inserted row based on the existence of some data that may or may not be in a table that is in another schema. The user account that I'm using to create the trigger does have the permissions to run the queries independently. In fact, I've had my trigger print the query I'm trying to run and was able to run it on it's own successfully. I should also note that I'm building the query dynamically by using the EXECUTE IMMEDIATE statement. Here's an example: CREATE OR REPLACE TRIGGER MAIN_SCHEMA.EVENTS BEFORE INSERT ON MAIN_SCHEMA.EVENTS REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW DECLARE rtn_count NUMBER := 0; table_name VARCHAR2(17) := :NEW.SOME_FIELD; key_field VARCHAR2(20) := :NEW.ANOTHER_FIELD; BEGIN CASE WHEN (key_field = 'condition_a') THEN EXECUTE IMMEDIATE 'select count(*) from OTHER_SCHEMA_A.'||table_name||' where KEY_FIELD='''||key_field||'''' INTO rtn_count; WHEN (key_field = 'condition_b') THEN EXECUTE IMMEDIATE 'select count(*) from OTHER_SCHEMA_B.'||table_name||' where KEY_FIELD='''||key_field||'''' INTO rtn_count; WHEN (key_field = 'condition_c') THEN EXECUTE IMMEDIATE 'select count(*) from OTHER_SCHEMA_C.'||table_name||' where KEY_FIELD='''||key_field||'''' INTO rtn_count; END CASE; IF (rtn_count > 0) THEN -- change some fields that are to be inserted END IF; END; The trigger seams to fail on the EXECUTE IMMEDIATE with the previously mentioned error. EDIT I have done some more research and I can offer more clarification. The user account I'm using to create this trigger is not MAIN_SCHEMA or any one of the OTHER_SCHEMA_Xs. The account I'm using (ME) is given privileges to the involved tables via the schema users themselves. For example (USER_TAB_PRIVS): GRANTOR GRANTEE TABLE_SCHEMA TABLE_NAME PRIVILEGE GRANTABLE HIERARCHY MAIN_SCHEMA ME MAIN_SCHEMA EVENTS DELETE NO NO MAIN_SCHEMA ME MAIN_SCHEMA EVENTS INSERT NO NO MAIN_SCHEMA ME MAIN_SCHEMA EVENTS SELECT NO NO MAIN_SCHEMA ME MAIN_SCHEMA EVENTS UPDATE NO NO OTHER_SCHEMA_X ME OTHER_SCHEMA_X TARGET_TBL SELECT NO NO And I have the following system privileges (USER_SYS_PRIVS): USERNAME PRIVILEGE ADMIN_OPTION ME ALTER ANY TRIGGER NO ME CREATE ANY TRIGGER NO ME UNLIMITED TABLESPACE NO And this is what I found in the Oracle documentation: To create a trigger in another user's schema, or to reference a table in another schema from a trigger in your schema, you must have the CREATE ANY TRIGGER system privilege. With this privilege, the trigger can be created in any schema and can be associated with any user's table. In addition, the user creating the trigger must also have EXECUTE privilege on the referenced procedures, functions, or packages. Here: Oracle Doc So it looks to me like this should work, but I'm not sure about the "EXECUTE privilege" it's referring to in the doc.

    Read the article

  • How do I exit a series of If / else conditions in a mysql trigger?

    - by ScArcher2
    I have a trigger that checks to see if certain fields changed during the update. If any of these fields changed I update another table. I'd like to "break" out of the if conditions as soon as I know that something changed. Is there a way to do this within a MySQL Trigger? What I have works, but It seems inefficient. CREATE TRIGGER profile_trigger BEFORE UPDATE ON profile FOR EACH ROW BEGIN DECLARE changed INTEGER; SET changed = 0; IF STRCMP(NEW.first_name, OLD.first_name) <> 0 THEN SET changed = 1; ELSEIF STRCMP(NEW.last_name, OLD.last_name) <> 0 THEN SET changed = 1; ELSEIF STRCMP(NEW.maiden_name, OLD.maiden_name) <> 0 THEN SET changed = 1; ELSEIF STRCMP(NEW.suffix, OLD.suffix) <> 0 THEN SET changed = 1; ELSEIF STRCMP(NEW.title, OLD.title) <> 0 THEN SET changed = 1; ELSEIF STRCMP(NEW.gender, OLD.gender) <> 0 THEN SET changed = 1; ELSEIF STRCMP(NEW.street, OLD.street) <> 0 THEN SET changed = 1; ELSEIF STRCMP(NEW.street2, OLD.street2) <> 0 THEN SET changed = 1; ELSEIF STRCMP(NEW.city, OLD.city) <> 0 THEN SET changed = 1; ELSEIF STRCMP(NEW.state, OLD.state) <> 0 THEN SET changed = 1; ELSEIF STRCMP(NEW.zip, OLD.zip) <> 0 THEN SET changed = 1; ELSEIF STRCMP(NEW.home_phone, OLD.home_phone) <> 0 THEN SET changed = 1; ELSEIF NEW.date_of_birth <> OLD.date_of_birth THEN SET changed = 1; END IF; IF changed > 0 THEN update other_table set updated = CURRENT_TIMESTAMP where id = NEW.id; END IF; END; |

    Read the article

  • Query executes with no error but not in trigger

    - by liaqat ali
    I am facing a strange problem in creating trigger in MS SQL. I have a query that executes with out an error but when I place it within trigger body, it gives error Invalid column name 'ScreenName'. I am placing whole trigger code here. Please trace the issue. CREATE TRIGGER [dbo].[tr_tbFieldLabels_FieldLabelLength] ON [dbo].[tbFieldLabels] AFTER INSERT AS Update tbFieldLabels Set TextBoxLength = (SELECT top 1 TextboxLength FROM tbFieldLabelsSource FLS WHERE FLS.ScreenName = Inserted.ScreenName AND tbFieldLabelsSource.SystemName = Inserted.SystemName) FROM tbFieldLabels , Inserted WHERE tbFieldLabels.ID = Inserted.ID GO Please help me ASAP.

    Read the article

  • Stored procedure and trigger

    - by noober
    Hello all, I had a task -- to create update trigger, that works on real table data change (not just update with the same values). For that purpose I had created copy table then began to compare updated rows with the old copied ones. When trigger completes, it's neccessary to actualize the copy: UPDATE CopyTable SET id = s.id, -- many, many fields FROM MainTable s WHERE s.id IN (SELECT [id] FROM INSERTED) AND CopyTable.id = s.id; I don't like to have this ugly code in trigger anymore, so I has extracted it to a stored procedure: CREATE PROCEDURE UpdateCopy AS BEGIN UPDATE CopyTable SET id = s.id, -- many, many fields FROM MainTable s WHERE s.id IN (SELECT [id] FROM INSERTED) AND CopyTable.id = s.id; END The result is -- Invalid object name 'INSERTED'. How can I workaround this? Regards,

    Read the article

  • Linq To Sql Entity Updated from Trigger

    - by James Helms
    I have a Table called Address. I have a Trigger for insert on that table that does some spacial calculations on the address that determines what neighborhood boundaries it is in. address = new Address { Street = this.Street, City = this.City, State = this.State, ZipCode = this.ZipCode, latitude = this.Latitude, longitude = this.Longitude, YearBuilt = this.YearBuilt, LotSize = this.LotSize, FinishedSize = this.FinishedSize, Bedrooms = this.Bedrooms, Bathrooms = this.Bathrooms, UseCode = this.UseCode, HOA = this.HOA, UpdateDate = DateTime.Now }; db.AddToAddresses(address); db.SaveChanges(); In the database i can clearly see that the Trigger ran and updated the neighborhoodID in the address table for the row. I tried to just reload that record to get the assigned id like this: address = (from a in db.Addresses where a.AddressID == address.AddressID select a).First(); In the debugger i can clearly see that the address.AddressID is correct, entity doesn't update in memory. Is there any work around for this?

    Read the article

  • using NEWSEQUENTIALID() with UPDATE Trigger

    - by Ram
    I am adding a new GUID/Uniqueidentifier column to my table. ALTER TABLE table_name ADD VersionNumber UNIQUEIDENTIFIER UNIQUE NOT NULL DEFAULT NEWSEQUENTIALID() GO And when ever a record is updated in the table, I would want to update this column "VersionNumber". So I create a new trigger CREATE TRIGGER [DBO].[TR_TABLE_NAMWE] ON [DBO].[TABLE_NAME] AFTER UPDATE AS BEGIN UPDATE TABLE_NAME SET VERSIONNUMBER=NEWSEQUENTIALID() FROM TABLE_NAME D JOIN INSERTED I ON D.ID=I.ID/* some ID which is used to join*/ END GO But just realized that NEWSEQUENTIALID() can only be used with CREATE TABLE or ALTER TABLE. I got this error The newsequentialid() built-in function can only be used in a DEFAULT expression for a column of type 'uniqueidentifier' in a CREATE TABLE or ALTER TABLE statement. It cannot be combined with other operators to form a complex scalar expression. Is there a workaround for this ? Edit1: Changing NEWSEQUENTIALID() to NEWID() in the trigger solves this, but I am indexing this column and using NEWID() would be sub-optimal

    Read the article

  • How to use SQL trigger to record the affected column's row number

    - by Freeman
    I want to have an 'updateinfo' table in order to record every update/insert/delete operations on another table. In oracle I've written this: CREATE TABLE updateinfo ( rnumber NUMBER(10), tablename VARCHAR2(100 BYTE), action VARCHAR2(100 BYTE), UPDATE_DATE date ) DROP TRIGGER TRI_TABLE; CREATE OR REPLACE TRIGGER TRI_TABLE AFTER DELETE OR INSERT OR UPDATE ON demo REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW BEGIN if inserting then insert into updateinfo(rnumber,tablename,action,update_date ) values(rownum,'demo', 'insert',sysdate); elsif updating then insert into updateinfo(rnumber,tablename,action,update_date ) values(rownum,'demo', 'update',sysdate); elsif deleting then insert into updateinfo(rnumber,tablename,action,update_date ) values(rownum,'demo', 'delete',sysdate); end if; -- EXCEPTION -- WHEN OTHERS THEN -- Consider logging the error and then re-raise -- RAISE; END TRI_TABLE; but when checking updateinfo, all rnumber column is zero. is there anyway to retrieve the correct row number?

    Read the article

  • SQL Server 2005: Insert a row in a table and update the same row

    - by vikas
    eg:table pkey --guid annualpay datefrom dateto--if null means current record percentannualincrease percent annual increase will be calculated only if there is a difference in newly inserted and previously existing last differing value. percentannualincrease = ([newannualpay-just previous pay(if different from current)]/newannualpay)*100 eg newid(),5000,today,null,0--very first row newid(),5000,today+1,null(*),0 newid,5500,today+2,null(*),?????????????--> need to be calculated before insert *--insert will close the previous record by updating dateto=null to todays date How can I do this stuff in a trigger???

    Read the article

  • Oracle - Trigger to check constraint before insert

    - by user1816507
    i would like to create a simple trigger to check a stored variable from a table. if the value of the variable is '1', then approve the insertion else if the value of the variable is '2', then prompt error message. CREATE OR REPLACE TRIGGER approval BEFORE INSERT ON VIP REFERENCING OLD AS MEMBER FOR EACH ROW DECLARE CONDITION_CHECK NUMBER; BEGIN SELECT CONDITION INTO CONDITION_CHECK FROM MEMBER; IF CONDITION_CHECK = '2' THEN RAISE_APPLICATION_ERROR (-20000, ' UPGRADE DENIED!'); END IF; END; But this trigger disable all the entries even when the condition value is '1'.

    Read the article

  • mySQL Trigger works after console insert, but not after script insert.

    - by Marcos
    Hello, I have a strange wird problem with a trigger: I set up a trigger for update other tables after an insert in a table. If i make an insert from mysql console, all works fine, but if i do inserts from external python script, trigger does nothing, as you can see bellow. When i insert from console, works fine, but insert THE SAME DATA from python script, doesn't works, i try changing the Definer to 'user'@'%' and 'root'@'%' but stills doing nothing. Any idea of what van be wrong? Regards mysql> select vid_visit,vid_money from videos where video_id=487; +-----------+-----------+ | vid_visit | vid_money | +-----------+-----------+ | 21 | 0.297 | +-----------+-----------+ 1 row in set (0,01 sec) mysql> INSERT INTO `prusland`.`validEvents` ( `id` , `campaigns_id` , `video_id` , `date` , `producer_id` , `distributor_id` , `money_producer` , `money_distributor` , `type` ) VALUES ( NULL , '30', '487', '2010-05-20 01:20:00', '1', '0', '0.009', '0.000', 'PRE' ); Query OK, 1 row affected (0,00 sec) mysql> select vid_visit,vid_money from videos where video_id=487; +-----------+-----------+ | vid_visit | vid_money | +-----------+-----------+ | 22 | 0.306 | +-----------+-----------+ DROP TRIGGER IF EXISTS `updateVisitAndMoney`// CREATE TRIGGER `updateVisitAndMoney` BEFORE INSERT ON `validEvents` FOR EACH ROW BEGIN if (NEW.type = 'PRE') THEN SET @eventcash=NEW.money_producer + NEW.money_distributor; UPDATE campaigns SET cmp_visit_distributed = cmp_visit_distributed + 1 , cmp_money_distributed = cmp_money_distributed + NEW.money_producer + NEW.money_distributor WHERE idcampaigns = NEW.campaigns_id; UPDATE offer_producer SET ofp_visit_procesed = ofp_visit_procesed + 1 , ofp_money_procesed = ofp_money_procesed + NEW. money_producer WHERE ofp_video_id = NEW.video_id AND ofp_money_procesed = NEW. campaigns_id; UPDATE videos SET vid_visit = vid_visit + 1 , vid_money = vid_money + @eventcash WHERE video_id = NEW.video_id; if (NEW.distributor_id != '') then UPDATE agreements SET visit_procesed = visit_procesed + 1, money_producer = money_producer + NEW.money_producer, money_distributor = money_distributor + NEW.money_distributor WHERE id_campaigns = NEW. campaigns_id AND id_video = NEW.video_id AND ag_distributor_id = NEW.distributor_id; UPDATE eventForDay SET visit = visit + 1, money = money + NEW. money_distributor WHERE date = SYSDATE() AND campaign_id = NEW. campaigns_id AND user_id = NEW.distributor_id; UPDATE eventForDay SET visit = visit + 1, money = money + NEW.money_producer WHERE date = SYSDATE() AND campaign_id = NEW. campaigns_id AND user_id= NEW.producer_id; ELSE UPDATE eventForDay SET visit = visit + 1, money = money + NEW. money_producer WHERE date = SYSDATE() AND campaign_id = NEW. campaigns_id AND user_id = NEW.producer_id; END IF; END IF; END //

    Read the article

  • Please verify the trigger created below for delete is correct or not?

    - by Parth
    Please verify the trigger created below for delete is correct or not? Its for the insertion of every field of deleted row in audit table.. Please reply whether this trigger will work for me? delimiter // CREATE TRIGGER audit_menu BEFORE DELETE ON menu FOR EACH ROW BEGIN INSERT INTO audit (menuid, field, oldvalue, changedone) VALUES (OLD.menuid, 'name', OLD.name, UNIX_TIMESTAMP() ), (OLD.menuid, 'age', OLD.age, UNIX_TIMESTAMP() ), (OLD.menuid, 'address', OLD.address, UNIX_TIMESTAMP() ), (OLD.menuid, 'sex', OLD.sex, UNIX_TIMESTAMP() ), (OLD.menuid, 'town', OLD.town, UNIX_TIMESTAMP() ) END;// delimiter ;

    Read the article

  • MYSQL trigger to select from and update the same table gives error #1241 - Operand should contain 1 column(s)

    - by Bipin
    when i try to select and update the same table mysql gives error error #1241 - Operand should contain 1 column(s) The trigger is DELIMITER $$ CREATE TRIGGER visitor_validation BEFORE INSERT ON ratingsvisitors FOR EACH ROW BEGIN SET @ifexists = (SELECT * FROM ratingcounttracks WHERE userid=New.vistorid AND likedate=New.likevalidation AND countfor=New.likeordislike); IF (@ifexists = NULL) THEN INSERT INTO ratingcounttracks(userid, likedate, clickcount,countfor) values (New.vistorid, New.likevalidation ,'1',New.likeordislike); ELSE UPDATE ratingcounttracks SET clickcount=clickcount+1 WHERE userid=New.vistorid AND likedate=New.likevalidation AND countfor=New.likeordislike; END IF; END$$

    Read the article

  • Query scope within a table trigger in an Oracle database

    - by sisslack
    I'm been trying to write a table trigger the queries another table that is outside the schema where the trigger will reside. Is this possible? It seems like I have no problem querying tables in my schema but I get: Error: ORA-00942: table or view does not exist when trying trying to query tables outside my schema. The documentation seems to elude to this notion, but it's not 100% clear to me.

    Read the article

  • Check constraint on table lookup

    - by bzamfir
    Hi, I have a table, department , with several bit fields to indicate department types One is Warehouse (when true, indicate the department is warehouse) And I have another table, ManagersForWarehouses with following structure: ID autoinc WarehouseID int (foreign key reference DepartmentID from departments) ManagerID int (foreign key reference EmployeeID from employees) StartDate EndDate To set new manager for warehouse, I insert in this table with EndDate null, and I have a trigger that sets EndDate for previous record for that warehouse = StartDate for new manager, so a single manager appears for a warehouse at a certain time. I want to add two check constraints as follows, but not sure how to do this do not allow to insert into ManagersForWarehouses if WarehouseID is not marked as warehouse Do not allow to uncheck Warehouse if there are records in ManagersForWarehouses Thanks

    Read the article

  • How do i stop continuous builds in CCNET dashboard?

    - by Heera
    I have successfully setup a CCNet web dashboard and everything is working fine has expected. And i have triggered a force build from CCNET and it ran successfully with out causing any error. but, the problem what i am facing is that, whenever i'm triggering the build from CCNET dashboard (Force) it's keeps on to build continuously again and again. Actually it should stop the build automatically right after the success of the latest build. can any one help me out, how to stop the continuous builds ???? Thanks in Advance !!!

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >