Determine which table was updated in database level trigger - sql

I am creating a database level trigger which should only perform a certain action based on which tables were updated.
With a regular trigger I would just use IF UPDATED(column).
Is there some way to determine not just the column that was updated but also the table?

You can't create DDL TRIGGER ON UPDATE
CREATE TRIGGER
DDL triggers, like standard triggers, execute stored procedures in
response to an event. But unlike standard triggers, they do not
execute in response to UPDATE, INSERT, or DELETE statements on a table
or view. Instead, they primarily execute in response to data
definition language (DDL) statements. These include CREATE, ALTER,
DROP, GRANT, DENY, REVOKE, and UPDATE STATISTICS statements. Certain
system stored procedures that perform DDL-like operations can also
fire DDL triggers.

Related

Is the BEFORE Trigger statement executed before the DDL statement?

Is the BEFORE trigger statement executed before DDL statements or is it inside a DDL statement?
I'm building a small DBMS and currently developing the DDL, and I'm confused about handling the BEFORE statement.
Here's not a defined behaviour for it:
https://web.csulb.edu/colleges/coe/cecs/dbdesign/dbdesign.php?page=sql/ddldml.php
Oracle describes the behaviour but not what can come inside the preceding or following trigger or whether they can be DDL statements or not:
https://www.oracletutorial.com/plsql-tutorial/oracle-trigger/
"BEFORE" is part of the DDL statement that defines the trigger. It describes when the trigger fires in relation to a DML command on a table: i.e. BEFORE or AFTER the change to the data is actually made. This allows you to validate or modify the new data as it is being applied, or to add or modify dependent data like a child table after the parent table update is complete.
While you can technically embed DDL into the body of a trigger using "execute immediate", it is typically considered very bad practice to do so. Is there a specific use case you are considering for including DDL statements in a trigger?

How do I get the performed operation and affected table from a database trigger in oracle?

How do I get the performed operation and affected table from a database trigger in oracle?
I want to create a trigger for a schema in Oracle which gets executed on drop or alter or create on database So I need something similar like inserting, updating, deleting but for DDL statements, and somehow I need to know the affected table and schema.
The documentation has a list of the event attribute functions that you can access. It looks like you'd want ora_sysevent for the event along with ora_dict_obj_name and ora_dict_obj_owner to identify the object in question.

Is there a way to default the trigger to run on specific user for DML operations?

I have a trigger on Table A in Database A which inserts data into Table b which is in Database B, both databases are on the same server.
A user with developer access to Table A in Database A is encountering an error when they perform dml operations as his role is restricted just to use Database A. Is there a way to default a trigger to run on a specific connection?
In SQL Server, triggers (and stored procedures and functions) have the EXECUTE AS clause. This gives you control over the permissions when the code is executed.

Column Constraint Sql 2008

I have been trying to find out if I can make a column Open on Insert, and closed on Update.
What I mean by that, is I need a column that I can give it a value only on Insert, but if I try to give it a value with Update, the statement would fail.
I am working with SQL 2008...
You can't do this with constraints - you need to use triggers for this.
A trigger is a special kind of stored procedure that automatically executes when an event occurs in the database server. DML triggers execute when a user tries to modify data through a data manipulation language (DML) event. DML events are INSERT, UPDATE, or DELETE statements on a table or view.

Is CRUD DDL or DML operation?

Is CRUD classified as DDL or DML or both.
CRUD being the operation Create Read Update and Delete
CRUD operations when applied to an SQL database map directly to DML statements. You have to bear in mind that the "C" in CRUD corresponds to the INSERT statement in SQL which creates an instance of something in a table. There is a CREATE statement in SQL that used for DDL operations but this is not the same sense of "Create" as in CRUD.
Create = INSERT
Read = SELECT
Update = UPDATE
Delete = DELETE
I'd say they're closer to Data Manipulation Language, because DDL is more about defining a schema where as DML is about working with objects within a defined schema. I propose the following map between DML and CRUD (using standard insert, create, update, delete methods from dml):
Create -- Insert
Read -- Select
Update -- Update
Delete -- Delete
However, I don't know if thinking of it as either DDL or DML will help you very much. CRUD isn't a language so much as a set of operations for handling objects you wish to expose via some interface.