I am wondering if there is a specific Insert or Update option in SSIS.
Will I have to do some coding if I want to let the program check if it is an update or insert?
Or can there be an option enabled so it will check itself if the PK exists then update and otherwise insert?
Kind regards
Just one solution
SSIS update insert
better update syntax
If there are more records it will be slow.
I don't know if I uderstand your problem properly. But I think SQL Server MERGE would be very useful here. And it's super-efficent.
More info here:
http://technet.microsoft.com/en-us/library/bb510625.aspx
Related
I have a confusing Problem.
I am using 5.6.12 Community Version.
I have an AFTER UPDATE Trigger, that is working correctly, when the table is called with for example
UPDATE test_table SET TestVariable = 2 WHERE TestIndex = 2;
But when I use
INSERT INTO test_table (TestIndex,TestVariable) VALUES (2,3) ON DUPLICATE KEY UPDATE TestVariable = 3;
the UPDATE-Trigger is not "triggered".
This is of course a heavily simplified case and has nothing to do with my current code. I have not found much information about this. In my opinion the UPDATE on a DUPLICTE KEY is internaly a normal UPDATE and should call my trigger.
Has anyone made similar observations, or can explain to me, why MySQL is behaving that way, or assure me, that I must have some error in my setup, because it should work?
I do NOT need a answer suggesting, that I should NOT use INSERT INTO ... ON DUPLICTE KEY ..., because
a) thats not the question
and
b) I can not easily modify the business application i currently work on.
Thank you so much for your Help
I have tested this on the smalles possible scale and came to a conclusion.
The Update trigger works, like you would expect it. It gets called by the ON DUPLICATE UPDATE. I could reproduce this by calling the queries from console.
The Update trigger is not called (as I reported) when I execute the query from my .net code, using the Oracle .net connector! I have installed the current version 6.9.8.0. To this moment I do not know, if this is a bug in the current version, or if this is a generall issue. I will investigate this further, but for this case, my question is answered.
The issue is for clerification not a MySQL problem, but a connector problem.
Thank you for your help, People.
MySQL has this incredibly useful yet proprietary record holding the "new row"(NEW).
I wonder if there is any SQL server command to replace the New in MySQL.
In mysql, in a trigger, I would use something like this.
INSERT INTO products(idProduct,idReference,date)
VALUES (NEW.idProduct,idReference,NOW());
However I don't know how if is it possible to do the same command but in Sql Server.
I hope I have been clear in my question.
If not explicit, or if it isn't possible to implement what I want, I apologize.
Thank you all.
In your trigger
INSERT products(idProduct,idReference,date)
SELECT idProduct, idReference, GETDATE()
FROM inserted
new is only available in a trigger if I'm not mistaken.
As SQL Server uses statement-level triggers and MySQL uses row-level triggers there is not direct equivalent to the concept of "the new row" in a trigger. Read the documentation on the inserted virtual table that is available in SQL Server.
Example usage: SQL Insert trigger to update INSERTED table values
I use SQL Server 2008.
I need to DENY any delete operations on a specific ROW in a Table.
I would like to know how can implement this feature at DB level.
Please provide a sample of T-SQL. Thanks for your time.
Create a trigger that throws an exception if the deleted row is your specific row.
Use INSTEAD OF DELETE trigger and ROLLBACK TRAN. Here is a good article on this.
I am fairly new to using mysql. I have an application that performs some basic querying. I am also trying to run a simple delete statement -
delete from mydb.mytable
This table is a simple 2 column table with not keys or triggers or anything defined. For some reason, the delete is not being performed. If I run the statement from MySql Workbench in the query window, it works fine. From the code, it does nothing. I am not seeing any error messages. I created a user with select, insert, update and delete rights to the schema. I am able to do the insert fine, but the delete does not seem to be working.
Is there a setting for mysql that I am missing that will not allow me to perform the delete?
Thanks for any thoughts.
Fist of all, check if
you are connected to the right database ;
you are using transaction and forgetting 'commit' ;
the user you use have enough permissions to delete from the table .
As a side notice, if you want to delete all records, you should use truncate instead of delete
Are you using transactions? My first guess is that your code might be issuing a BEGIN TRANSACTION without a COMMIT.
We would have to see some of your code to answer the question.
My guess is that you are not calling commit from your code. You can configure MySQL to auto-commit your queries, but this is usually not what you want.
I know that triggers can be used on insert, update and delete, but what about a trigger (or sort of) on a select statement. I want to use a trigger to insert data on a table B when it is selected an existent record on a table A, it could be possible?.
Thanks in advance.
You should design your application so that database access occurs only through certain methods, and in those methods, add the monitoring you need.
Not exactly a trigger, but you can:
CREATE FUNCTION myFunc(...) BEGIN INSERT INTO myTable VALUES(...) END;
And then
SELECT myFunc(...), ... FROM otherTable WHERE id = 1;
Not an elegant solution, though.
It is not possible in the database itself.
However there are monitoring/instrumentation products for databases (e.g. for Sybase - not sure about MySQL) which track every query executed by the server, and can do anything based on that - usually store the query log into a data warehouse for later analysis, but they can just as well insert a record into table B for you, I would guess.
You can write an application which will be monitoring the query log and doing something when a select occurs. A pretty crude way to solve the problem though...