Violating the constraint in an update statement : Update « Insert Delete Update « SQL Server / T-SQL Tutorial






7> CREATE TABLE MySavings(
8>     AccountNum Int NOT NULL,
9>     Amount Money NOT NULL
10> );
11> GO
1>
2> CREATE TABLE MyChecking(
3>     AcountNum Int NOT NULL,
4>     Amount Money NOT NULL
5> );
6> GO
1> ALTER TABLE MyChecking ADD CONSTRAINT ckMinBalance
2> CHECK (Amount > $100.00)
3> GO
1>
2> INSERT MySavings VALUES (12345, $1000.00)
3> GO

(1 rows affected)
1>
2>
3> INSERT MyChecking VALUES (12345, $1000.00)
4> GO

(1 rows affected)
1>
2>
3> BEGIN TRANSACTION
4> UPDATE MyChecking SET Amount = Amount - $990.00
5> WHERE AcountNum = 12345
6> UPDATE MySavings SET Amount = Amount + $990.00
7> WHERE AccountNum = 12345
8> COMMIT TRANSACTION
9> GO
Msg 547, Level 16, State 1, Server J\SQLEXPRESS, Line 4
The UPDATE statement conflicted with the CHECK constraint "ckMinBalance". The conflict occurred in database "master", table "dbo.MyChecking", column 'Amount'.
The statement has been terminated.

(1 rows affected)
1>
2> drop table MySavings;
3> drop table MyChecking;
4> GO








2.5.Update
2.5.1.The syntax of the UPDATE statement
2.5.2.Syntax of UPDATE with a Join
2.5.3.An UPDATE statement that updates all the Billings for a Banker based on the Banker's name
2.5.4.An UPDATE statement that changes the terms of all Billings for Bankers in three states
2.5.5.Limiting Rows to Be Updated
2.5.6.Assigning Update Values Using Subqueries
2.5.7.An UPDATE statement that uses an arithmetic expression to assign a value to a column
2.5.8.Updating using two subqueries.
2.5.9.Updating Data Using the CASE Expression
2.5.10.An UPDATE statement that assigns the maximum due date in the table to a specific Billing
2.5.11.Violating the constraint in an update statement
2.5.12.SET other columns to their default value
2.5.13.Change the phone number of authors living in Gary, IN, back to the DEFAULT value
2.5.14.An UPDATE statement with top
2.5.15.Update table in a transaction
2.5.16.Updating Large Value Data Type Columns with WRITE