dml

SQL DML: Incorrect date value (MySQL)

强颜欢笑 提交于 2019-12-04 08:14:47
I created a table in my database: CREATE TABLE official_receipt( student_no INT UNSIGNED, academic_year CHAR(8), trimester ENUM('1', '2', '3'), or_no MEDIUMINT UNSIGNED, issue_date DATE NOT NULL, received_from VARCHAR(255) NOT NULL, amount_of DECIMAL(8,2) NOT NULL, issued_by VARCHAR(255), doc_type ENUM('FULL', 'DOWN', 'INST') NOT NULL, form_of_payment ENUM('CASH', 'INST') NOT NULL, PRIMARY KEY (student_no, academic_year, trimester, or_no) ); I inserted some values: INSERT INTO official_receipt(student_no , academic_year, trimester, or_no, issue_date, received_from, amount_of, issued_by, doc

Combine stored procedure and query in T-SQL

不羁岁月 提交于 2019-12-03 09:58:09
How do I combine executing of a stored procedure and using its result or parameters in a regular SQL query? For example I would like to do something like the following: -- passing result of SELECT to SP SELECT a, b FROM t EXEC my_sp a, b -- passing result of SP to INSERT INSERT INTO t EXEC my_sp a, b etc. KM. no, you need to use a temp table create table #results (col1 int, col2 varchar(5) ...) INSERT INTO #results EXEC YourProcedure @parma... then you can join to it SELECT * FROM YourTable y JOIN #results r ON ... .... if you don't know the columns and data types from the procedure you can

SQL Server Trigger switching Insert,Delete,Update

两盒软妹~` 提交于 2019-12-03 07:30:56
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, I will show you a simple way to check this in SQL Server 2000 or 2005 (you forgot to mention which version you are using), but in general I agree with Remus that you should break these up

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

自作多情 提交于 2019-12-02 21:08:08
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 HelloWorldHistory (hwh_action, ..long column list..) select 'INSERT', helloWorld.id, helloWorld.text ... and more from

Unit testing DDL statements that need to be in a transaction

删除回忆录丶 提交于 2019-12-02 11:01:06
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 problem because the DDL statements perform implicit commits. If an error occurs after a DDL statement has

Oracle - How does Oracle manage transaction specific DML statements

别来无恙 提交于 2019-12-02 03:40:30
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 haven't even committed the transaction yet. Oracle creates an index to enforce the primary key constraint

How to dynamically change the index value with SQL DML

試著忘記壹切 提交于 2019-12-01 10:33:46
I am a beginner in XML with SQL. How can I specify index within an insert statement as below. The following statement gives throws exception with invalid path to update. set @xmldata.modify('insert <Test>Test1</Test> after (/xyz/abc)[sql:variable("@index")]') sql:variable() Function (XQuery) has some examples, but that doesn't speak about changing the index but other part of the statement. Did you check out this article. http://technet.microsoft.com/en-us/library/ms175466.aspx SELECT @myDoc set @myDoc.modify(' insert <BikeFrame>Strong long lasting</BikeFrame> after (/Root/ProductDescription

How to dynamically change the index value with SQL DML

做~自己de王妃 提交于 2019-12-01 08:42:08
问题 I am a beginner in XML with SQL. How can I specify index within an insert statement as below. The following statement gives throws exception with invalid path to update. set @xmldata.modify('insert <Test>Test1</Test> after (/xyz/abc)[sql:variable("@index")]') sql:variable() Function (XQuery) has some examples, but that doesn't speak about changing the index but other part of the statement. 回答1: Did you check out this article. http://technet.microsoft.com/en-us/library/ms175466.aspx SELECT

Oracle之PL/SQL学习笔记之触发器

ぃ、小莉子 提交于 2019-11-30 22:14:04
Oracle之PL/SQL学习笔记之触发器 触发器是许多关系数据库系统都提供的一项技术。在ORACLE系统里,触发器类似过程和函数,都有声明,执行和异常处理过程的PL/SQL块。 触发器在数据库里以独立的对象存储,它与存储过程和函数不同的是,存储过程与函数需要用户显示调用才执行,而触发器是由一个事件来启动运行。 即触发器是当某个事件发生时 自动地隐式运行 。并且,触发器 不能接收参数 。所以运行触发器就叫触发或点火(firing)。ORACLE事件指的是对数据库的表进行的INSERT、 UPDATE及DELETE操作或对视图进行类似的操作。ORACLE将触发器的功能扩展到了触发ORACLE,如数据库的启动与关闭等。所以触发器常用来完成由数据库的完整性约 束难以完成的复杂业务规则的约束,或用来监视对数据库的各种操作,实现审计的功能。 触发器的种类有很多,这儿我们主要学习DML触发器 1. 触发器的组成 触发器组成: l 触发事件: 引起触发器被触发的事件。 例如:DML语句(INSERT, UPDATE, DELETE语句对表或视图执行数据处理操作)、DDL语句(如CREATE、ALTER、DROP语句在数据库中创建、修改、删除模式对象)、数据库系统事件(如系统启动或退出、异常错误)、用户事件(如登录或退出数据库)。 l 触发时间 :即该TRIGGER 是在触发事件发生之前

Select the SECOND LAST record in each group

别等时光非礼了梦想. 提交于 2019-11-30 14:29:01
There is a table Remark that contains data as shown below: SerialNo | RemarkNo | Desp ============================================= 10 | 1 | rainy 10 | 2 | sunny 11 | 1 | sunny 11 | 2 | rainy 11 | 3 | cloudy 11 | 4 | sunny 12 | 1 | rainy What query will return the following result: 10 | 1 | rainy 11 | 3 | cloudy 12 | null | null That is, the second last record in each group should be returned? Assuming all the RemarkNo for a SerialNo are continuous. The larger the remark number, the later the remark was made. Hence, the second last RemarkNo for SerialNo 10 is 1 with Desp 'rainy'. Try: select s