Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
We had created a trigger for inserting a set of rows.
I want to schedule this trigger automatically and insert these data into another table. i.e, it has to execute automatically based on the period given.
Kindly suggest the possibilities steps for this.
Here i give you the clear explanation about the operation,
My project to transfer the data from MS SQL database table to MY SQL Database table. This event has to be scheduled. I have to select few fields from MS Sql table and that selected data to be transfer to My Sql table Automatically based on Scheduled.
You could use mysql event scheduler to configure and run your job.
Please have look into
http://dev.mysql.com/doc/refman/5.1/en/events-configuration.html
First, Trigger is one database object and trigger created over the any physical table. this is depends on table action so at every action of table trigger will execute.
we cant schedule trigger to execute on perticluar time.
There is alternative solution is: Enable and Disable trigger using scedule SQL Job.
Script is :
--To Enalble Trigger
ENABLE TRIGGER [Trigger_Name] ON [TableName]
GO
--To Disable Trigger
DISABLE TRIGGER [Trigger_Name] ON [TableName]
GO
If you're using MS SQL, then you can use SQL Server Agent to schedule a job/task to execute whatever you need done.
You can read more about it here http://msdn.microsoft.com/en-us/library/ms191439.aspx
Your best bet maybe to create a stored procedure and then in the scheduled job, simply execute that stored procedure to run.
Alternatively, if you don't have SQL Server Agent (requires full version of MS SQL not SQL Server Express) then you could possibly look into using Windows Scheduled Task to schedule a batch file to run periodically, making a call to the sqlcmd utility http://technet.microsoft.com/en-us/library/ms165702(v=sql.105).aspx which you should be able to setup to execute your stored procedure.
Hope this helps.
Related
I have a client aplication work with a database on my server. That application insert/update a table on my database when human operator close application. I need to change some row of my table in database after application update/insert my table and closed.
How can i tell to oracle database execute procedure or trigger when application closed by human operators?
Oracle can understand time of a user close application that work with database? If yes, can i write job or trigger to run at that's time?
If no, have I choice to do that?
My Database: oracle 10g
The trigger is an prcedure call automatically.
In the trigger, you make an AFTER UPDATE or INSERT or both statement.
Then you program the specific row you need to change.
After an insert for exemple Oracle execute the trigger and change the rows.
Hope it helps you a litte bit ;)
You don't have specified much about Application (which is operated by human). And you can trigger procedure or execute procedure in oracle by handling appropriate event in Application (For example Application_End(), Form_Close() event in dot net).
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
We can go for transaction management in procedure but we can’t go in function, I have seen this statement at multiple places, while we ask for difference between function & procedure, But I did below test in oracle and **I can see its working fine for function also**. Can anybody please let me know what thing am I missing about above statement, because this statement looks completely wrong to me?
select * from test; *(test table having single column "name varchar(2)")
create or replace function FUNTest
return number as result NUMBER(6,2);
BEGIN
SAVEPOINT fn_fntest;
insert into test(NAME) values('Dinesh');
ROLLBACK TO fn_fntest;
return 1;
END;
/
Begin
DBMS_OUTPUT.PUT_LINE(FUNTest());
end;
/
Purpose of function is different from procedure.
Function: Supposed to do some calculation and return some value(most
of the cases)
Procedure: Perform some operation based on data/column.It manages transaction as well, because you will definately be storing new data somewhere.
Now talking about transaction management in function, well it depends on calling mechanism of function.
If your function is having transactional statement like commit/rollback then it should be called from some other block which is capable of handling transaction like procedure or anonymous block(your case).
If you call that same function from select statement like "select funtest() from dual;" then you will get error as select statement is not capable of opening transaction.
If you still want to call any function having transactional statement from non-transactional body(select statement) then your function should be capable of opening separate independent transaction(PRAGMA AUTONOMOUS_TRANSACTION).
Please refer to http://www.datacoons.com/content/transaction.php for more information on transaction management.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have deleted a record from my table and after executing rollback command it shows "command completed successfully" but when i check it using select statement the table is still looking empty? why ?
Some database connection methods such as ODBC default to what's known as "autocommit" mode - that is, the database connection automatically issues a COMMIT after each statement is executed. JDBC does the same thing. I cannot say if this is what's happening in your case, but if so there's no way to do a ROLLBACK. Best of luck.
Rollback command takes you back to the latest committed state of the table.I guess your delete query might have contained some statement that committed the change(deletion of record).
Jason Clark,
I did a test using MySql and use the "begin", "delete" and "rollback", used the following SQL (an example):
begin; delete from aluno where id = 1; rollback;
In PostgreSQL, SQL syntax is the same and also worked.
Are you sure you used the correct SQL? I might have been some mistake? Is it really necessary to use "begin transaction" instead of just "begin"?
I hope this helps!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
When one wants to update records in database using Data Manipulation Language, what would be right terminology to use:
UPDATE RECORDS IN TABLE VIA STORED PROCEDURE or
UPDATE RECORDS IN TABLE VIA SCRIPT (or UPDATE SCRIPT)
something else...
NOTE: I know that procedure is not same as script, I wrote question in rush. Real question is if you want to write to your DBA that the defect could be fixed by using (1) or (2) or (3) what would be the right choice. Sorry for not being precise.
If you want to DBA fix some defect, best approach is to write a script file with UPDATE statements, and save it for later use.
If you want that someone else (Job, DBA, App Code) frequently execute same code for updating records in table, then write stored procedure.
Good thing is that you can pass a parameter to stored procedure to affect on range of rows which will be updated.
ONE IMPORTANT THING: Stored procedure are optimized from SQL Optimizer and SQL creates most effective execution plan for it. When you execute it again, SQL find cached execution plan for that procedure and apply it. In this way, you achieve better performance when using stored procedure over script.
A "script" sounds to me like one or more statements that are sent to the database, to perform some action.
A "stored procedure" is that same bunch of statements, but already stored in the database so it can be activated with a simple command.
"Update via stored procedure" is not a synonim to "update via script", so why do you choosing either one or another as term?
Stored procedure - is an object (yes, technically it is some kind of scripit) created and stored in database.
Script - is just a script (sequence of statements). It can be stored in file or just created and executed "on the fly".
If you use just one update statement, then the most appropriate expression is "update records in table via update statement". If you use set of update statements, then it will be a script.
Procedure is an another DBMS object, usually called stored procedure. You can also define a procedure that update data in the database.
Non of the options fit me very well. Sure, if you know an update is being made from a Stored Procedure specifically, that would be fine to use. But an update can be done from many other ways and a Stored procedure can do many other things than just update.
I usually talk about queries and statements, for example:
Update records in a table via an update statement within a Stored Procedure
As for the use of script, I'm personally not that fond of it. There are already many more specific ways to talk about scripts, like Stored procedures, user defined functions, etc. That, for me, is a collection of statements and/or queries.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
When I need more information about table and its column I always use the build-in stored procedure 'sp_help xxxxx' to retrieve more information.
What other method or SP are usable to use?
You can use sp_depends to get want tables and columns it is using
EXEC sp_depends yourProcedure;
I prefer to use dynamic management views (DMV) and functions (DMF) to get more information about database server..........The DMV/DMF's have been organized into the following different groups:
Common Language Runtime related
Database Mirroring related
Execution related
Full-Text Search related
Index related
I/O related
Query Notifications related
Replication related
Service Broker related
SQL Server Operation system
Transaction related
Just browsing to the table in SQL Server Management Studio will tell you quite a lot.
Table/Column definitions.
Indexes
Triggers
Constraints
Primary/Foreign Keys
Dependancies
etc, etc
Look into the sysobjects view (http://msdn.microsoft.com/en-us/library/ms177596.aspx):
SELECT * FROM sysobjects WHERE type = 'P'
Other sys view can be handy too.
How about using sp_columns
EXEC sp_columns #table_name = N'TableName'
Using sp_helptext will come in handy, it gives you the definition of a stored procedure, function or view.
I.E.:
CREATE PROC usp_MyProcedure AS SELECT * FROM TABLE
Runing the following will output the query above.
Exec sp_helptext 'usp_MyProcedure'