Sql server trigger : Invalid 'inserted' object name - sql

I have a table that I want to test on it a trigger I try to SELECTED the line of
the query to see what the table contains but an error appear and In all MY sql project inserted and deleted table doesn't work for me this is what I wrote
the is the error that appear (On the Image)
CREATE TRIGGER TR
on Ligne
for insert
as
begin
select * from inserted
end
please is there any solution for this problem and thanks
I find that when i hover on inserted it show me this

Have you made sure intellisense is enabled in SSMS ?
Go to Tools >> Options >> Text Editor >> Transact-SQL >> IntelliSense
Then - if it is enabled - sometimes it helps to refresh the local cache:

Have you tried placing an i at the back of the keyword, inserted?
CREATE TRIGGER TR
on Ligne
for insert
as
begin
select * from inserted i
end

Related

trying to use trigger

I'm trying to activate a trigger when a new employee is added. the trigger should store the username of the person that has done the insert and the time it happened. Using Oracle database.
So far my code for the trigger is:
CREATE OR REPLACE TRIGGER insert_2
AFTER INSERT ON employees
for each row
DECLARE
vUser varchar(50);
begin
select user into vUser from dual;
insert into audit_cheker1 (date_create, inserted_by)
values (sysdate(), vUser);
END;
/
The trigger works but after I try to insert a new record it doesn't work and tells me error in the trigger.
The error message is telling you your trigger is invalid, that is it contains syntax errors and cannot be compiled. So you need to fix the compilation errors.
There are several ways to find errors. You can run a query:
select * from user_errors
where type = 'TRIGGER'
and name = 'INSERT_2'
/
You could use the SQL*Plus command show errors after the CREATE TRIGGER statement.
Or, as it seems you're using SQL Developer, you could open the trigger in the Object Navigator. You'll see the tab has several panes, one of which is labelled Errors. Open that pane to see what's wrong.
Here is one for free: although sysdate is technically a function it is a special one. It never takes any parameters and calling it with brackets is wrong. Remove these brackets: sysdate().

Oracle APEX 5 Select List Error ORA-01400

i have a Problem with Oracle APEX 5.
I have a Popup with Textareas and with a Select List. I can write the Data of the Textareas without Problem into my Database, but i can not write the Data of my Select list into my Database. I alway get the Error ORA-01400 Server Error Insert of NULL imposible.
I also tried to write Hard data in the Table so i Changed the PLSQL to:
begin
INSERT INTO STATUS_TO_CHANGE (CHANGE_ID, CHANGE_STATUS_ID)
VALUES (:P2_CHANGE_ID, '43');
end;
and it worked without Problems :(
Maybe someone can help me :O
I use a own button to save the Textarea and a own button for the select list.
Code of my Dynamic Action:
begin
INSERT INTO STATUS_TO_CHANGE (CHANGE_ID, CHANGE_STATUS_ID)
VALUES (:P2_CHANGE_ID, :P2_STATUS_DESCRIPTION);
end;
Name of the Select List: P2_Status_Description
Select List with save Button .jpg
Error MessageData in the Table Change_Status which is shown in the LOV in the Select list
Thanks to all :)
I can't see images right now.
Anyway: this is, I believe, a "Execute PL/SQL Code" dynamic action, right? You put that BEGIN-END block into the "PL/SQL Code", but - did you put P2_CHANGE_ID and P2_STATUS_DESCRIPTION into Items to Submit? If not, do it and then try again.

How to alter table add column then update within single script?

We have a custom database updater which runs various SQL scripts on SQL Server. Some of the scripts need to add a new column to a table, then populate the values, in a single script, within a transaction:
using (var scope = new TransactionScope()) {
... alter table MyTable add FOOBAR int;
... update schappointment set FOOBAR = 1;
}
Problem is, SQL spits back "Invalid column name 'FOOBAR' because the "alter table" command hasn't taken effect. Wrapping it in exec() makes no difference:
... exec('alter table MyTable add FOOBAR int;')
... update schappointment set FOOBAR = 1;
It works OK within SQL Management Studio because it splits it up with GO commands (which I know are not valid T-SQL commands).
I'd prefer not to create any new dependencies in the project.
My preference is not to split the schema & data scripts as this doubles the number of scripts for no reason other than to make SQL happy.
How can I solve this?
You can't do this exactly in a single statement (or batch) and it seems the tool you are using does not support GO as a batch delimiter.
You can use EXEC to run it in a child batch though.
ALTER TABLE A
ADD c1 INT, c2 VARCHAR(10);
EXEC('
UPDATE A
SET c1 = 23,
c2 = ''ZZXX'';
');
NB: All single quotes in the query need to be doubled up as above to escape them inside a string literal.
I tried this approach this is working.
alter table then update in single statement
Our solution was to sprinkle "GO" commands throughout the scripts, and customize our script execution function to split them up and run them seperately.
This mimics what SQL management studio does and seems to work.

Error in the sql command line

Every time I insert new data to my table using the command line, it is inserted successfully (and I check my insertion by typing select * from table_name;) but when I close the command line and open it again and write the sql statement which (select * from table_name;) it says that there are no rows selected. I mean the inserted row is not saved in the database.
Please can someone help me to know the problem?
Use COMMIT; to apply your SQL statements

Oracle - Trigger is created, but gives error anytime data is updated

I'm creating the following trigger:
CREATE TRIGGER Trigger_UpdateTrainingDelivery
AFTER DELETE OR INSERT OR UPDATE OF STARTDATE
ON TPM_TRAININGPLAN
BEGIN
UPDATE TPM_PROJECTVERSION V
SET TRAININGDELIVERYSTART = (SELECT MIN(STARTDATE) FROM TPM_TRAININGPLAN WHERE PROJECTID=V.PROJECTID AND VERSIONID=V.VERSIONID AND TRAININGPLANTYPE='prescribed')
END;
When I create it, I get a warning:
Warnings: --->
W (1): Warning: execution completed with warning
<---
However, it's still created it anyway. When I then modify a row in TPM_TRAININGPLAN, I get an error:
>[Error] Script lines: 12-12 ------------------------
ORA-04098: trigger 'TPMDBO.TRIGGER_UPDATETRAININGDELIVERY' is invalid and failed re-validation
Script line 12, statement line 1, column 7
Is there something wrong with my trigger? I can run the UPDATE statement in the trigger by itself and it runs fine, so I don't think there's anything wrong with that.
It appears that you are missing a semicolon at the end of your UPDATE statement.
If you query USER_ERRORS, you'll get the same error information that SQL*Plus will give you with the SHOW ERRORS command without needing to have access to SQL*Plus.
SELECT line, position, text
FROM user_errors
WHERE name = 'TRIGGER_UPDATETRAININGDELIVERY'
ORDER BY sequence
What was the error being reported during compilation?
SQL> show errors trigger trigger_updatetrainingdelivery
Ok I figured this out. It's actually a bug in Aqua Data Studio, which I'm using to run the query. For some reason, it doesn't handle semi-colons within the triggers correctly. I will report this bug, but I did find a workaround:
File->Options->General
Uncheck: ';' Statement separator