dml

Oracle - How does Oracle manage transaction specific DML statements

狂风中的少年 提交于 2020-01-11 10:48:09
问题 Imagine I have this simple table: Table Name: Table1 Columns: Col1 NUMBER (Primary Key) Col2 NUMBER If I insert a record into Table1 with no commit... INSERT INTO Table1 (Col1, Col2) Values (100, 1234); How does Oracle know that this next INSERT statement violates the PK constraint, since nothing has yet been committed to the database yet. INSERT INTO Table1 (Col1, Col2) Values (100, 5678); Where/how does Oracle manage the transactions so that it knows I'm violating the constraint when I

How to copy an inserted,updated,deleted row in a SQL Server trigger(s)

人走茶凉 提交于 2019-12-31 10:46:11
问题 If a user changes table HelloWorlds , then I want 'action they did', time they did it, and a copy of the original row insert into HelloWorldsHistory . I would prefer to avoid a separate triggers for insert, update, and delete actions due to the column lengths. I've tried this: create trigger [HelloWorlds_After_IUD] on [HelloWorlds] FOR insert, update, delete as if @@rowcount = 0 return if exists (select 1 from inserted) and not exists (select 1 from deleted) begin insert into

Use a UDF as the default value in a table column in SQL Server

独自空忆成欢 提交于 2019-12-31 01:47:54
问题 I created a scaler UDF (called sCurrentAppUser()) in SQL Server 2012 Express and I would like to use this UDF as a default value when defining a table. But every time I try, I get an error of "'sCurrentAppUser' is not a recognized built-in function name." Since I can't post more than two links yet (reputation), I'll link to my research and references in a comment. Here's my UDF: ALTER FUNCTION [dbo].[sCurrentAppUser] () RETURNS nVarChar(128) AS BEGIN DECLARE @CurrentAppUser nVarChar(128) IF

What's the PostgreSQL equivalent of MSSQL's CONTEXT_INFO?

江枫思渺然 提交于 2019-12-29 08:55:34
问题 In relation to my other question "What’s the best way to audit log DELETEs?". What's the PostgreSQL equivalent of CONTEXT_INFO? [EDIT] I want to log deletes using trigger, but since i'm not using the database user as my app's logical user, I cannot log the CURRENT_USER from the trigger code as the user who deleted the record. But for INSERT and UPDATE it is possible to log the record changes from trigger since you can just add a user field in the record, say inserted_by and last_updated_by,

Reversing order of results in START WITH LPAD SQL query

依然范特西╮ 提交于 2019-12-25 01:53:06
问题 SELECT LPAD('*', 2*level-1)||SYS_CONNECT_BY_PATH(unit_data, '/') "battle_unit_id" FROM battle_units where connect_by_isleaf = 1 START WITH battle_unit_id= 600 CONNECT BY PRIOR parent_id = battle_unit_id; returns */F-16/Jet powered aircraft/Air/Doctrine where, F-16 is the great-grandchild of Doctrine. Question 1 I would like to reverse this order such that i get the following: */Doctrine/Air/Jet powered aircraft/F-16 Question 2 Currently, the battle_units table have battle_unit_id from 1 to 50

SQL Server Trigger switching Insert,Delete,Update

最后都变了- 提交于 2019-12-21 01:59:23
问题 Hello is possible to switch between DML commands/operations (Insert,Delete,Update) on Trigger Body?, I try to snippet some T-SQL for understand me better : CREATE TRIGGER DML_ON_TABLEA ON TABLEA AFTER INSERT,DELETE,UPDATE AS BEGIN SET NOCOUNT ON; CASE WHEN (INSERT) THEN -- INSERT ON AUX TABLEB WHEN (DELETE) THEN -- DELETE ON AUX TABLEB ELSE --OR WHEN (UPDATE) THEN -- UPDATE ON AUX TABLEB END END GO Thanks, 回答1: I will show you a simple way to check this in SQL Server 2000 or 2005 (you forgot

Unit testing DDL statements that need to be in a transaction

℡╲_俬逩灬. 提交于 2019-12-20 05:52:48
问题 I am working on an application that uses Oracle's built in authentication mechanisms to manage user accounts and passwords. The application also uses row level security. Basically every user that registers through the application gets an Oracle username and password instead of the typical entry in a "USERS" table. The users also receive labels on certain tables. This type of functionality requires that the execution of DML and DDL statements be combined in many instances, but this poses a

How can I perform DML operations in SQL Server?

大憨熊 提交于 2019-12-13 02:01:19
问题 I want to know how I can perform DML operations on a view composed of more than 1 table. Ie. if I have a view that joins three tables, is there a way I can can perform DML operations like UPDATE , DELETE , etc. on this view? 回答1: if the DML operation (Update/Delete/Insert) effects only one underlying table of your View the chances are you can do it. if the the operation effects more than one table you need to use Instead of Triggers . Instead of triggers, triggers instead of the triggering

Cascading diamond shaped deletes in SQL

谁都会走 提交于 2019-12-12 12:29:11
问题 If I have a simple User table in my database and a simple Item table with a User.id as a foreign key thus: (id UNIQUEIDENTIFIER DEFAULT (NEWID()) NOT NULL, name NVARCHAR (MAX) NULL, email NVARCHAR (128) NULL, authenticationId NVARCHAR (128) NULL, createdAt DATETIME DEFAULT GETDATE() NOT NULL, PRIMARY KEY (id)) CREATE TABLE Items (id UNIQUEIDENTIFIER DEFAULT (NEWID()) NOT NULL, userId UNIQUEIDENTIFIER NOT NULL, name NVARCHAR (MAX) NULL, description NVARCHAR (MAX) NULL, isPublic BIT DEFAULT 0

How to pass index value from a node in XML DML with SQL

a 夏天 提交于 2019-12-12 01:29:43
问题 Starting with XML DML in SQL Server, pretty fine at the moment, but I am facing this challenge. I need to iterate through some defined nodes in XML data stored in SQL Server. Already check this as reference, it gives a clue but still I did not figure it out how to send a SQL variable as an index in XML DML Reference. Suppose the following XML data: <materials> <est_mat> <pos>20</pos> <item>BOX</item> <qty>0.004</qty> </est_mat> <est_mat> <pos>30</pos> <item>xxx-xxx-xxx01</item> <qty>1</qty> <