create trigger for insert update delete sql server
create trigger for insert update delete sql server
Learn about create trigger for insert update delete sql server, we have the largest and most updated create trigger for insert update delete sql server information on alibabacloud.com
, but today we want to know the trigger application. What content should be written in the trigger to simplify the above Code? Create a trigger.
The syntax for creating a trigger is long and simplified:Reference: Create
today we want to know the trigger application. What content should be written in the trigger to simplify the above code? Create a trigger.The syntax for creating a trigger is long and simplified:QUOTE:CREATE TRIGGERTrigger nameONTable name/View Name{ FOR | AFTER | INSTEAD}{[DELETE
the data of the deleted table is the data before or after the update.Create a TriggerGrammarCreate a TriggerGrammarCreate Trigger Tgr_nameOn table_nameWith encrypion– encryption triggerFor update ...AsTransact-SQL# Create Insert Type Tr
This article is a MySQL database insert, UPDATE, delete and replace statements in the use of detailed analysis of the introduction, the need for friends to refer to the
MySQL database insert and UPDATE statements Introduction: The SQL
Label:Type: Reprint
The SQL UPDATE trigger can get information about the row being update, and the friend you need can refer to it.
Copy CodeThe code is as follows:Create Trigger TgnameOn TBFor updateAsIf Update (recommend)Be
Grammar:Trigger on the INSERT, UPDATE, or DELETE statement to a table or view (DML Trigger)CREATE TRIGGER [schema_name.] Trigger_nameOn {table | view}[With {for | After | INSTEAD of}{[INSERT
, triggers can be used to implement complex integrity constraints on tables.
2. SQL Server creates two special tables for each trigger: The Inserted Table and the Deleted table. These two tables are maintained by the system and exist in the memory instead of in the database. The structure of these two tables is always the same as that of the table to which the
Speaking of synchronization, in fact, "homework" schedule stored procedures to operate the data, add, delete, change, all in the inside, combined with triggers, cursors to achieve, about job scheduling, using 5 seconds to run a "second-level operation", so basic even faster "synchronization"Do is SQL Server to the Oracle side synchronization, first set up on the
Views are often used recently, but MSSQL Server does not allow update operations on views associated with more than two base tables. Due to the project's needs, I spent a night studying it. Take some time to record the process and experience.
Let's take a look at the authoritative saying:
Updatable View:
Microsoft SQL Server
--Create, delete temporary tables
--The first way
create TABLE #tmp (name varchar (255), id int)-
-The second way
select COUNT (id) as Storynum,
sum (convert (Numeric (10,2), Case if IsNumeric (code) =1 then code else 0 end)) As Codenum,
sum ((Case when IsNumeric (realcode) =1 then convert (numeric (10,2), realcode) else 0.0)) as Realcodenum,
tdtname,cy
needs to be displayed in the result setStatisticsInformation, The optimizer will select the best execution method, because the optimizer willStatisticsInformation.
InCreateWhen indexing, SQLServer will be on the index ColumnCreateStatisticsInformation. To put it simply,StatisticsInformationThat is, the data that can describe the data distribution in the index or column.
Query selectivity:
Formula: Total number of non-duplicated data in a column/total number of data in a column
The higher the s
Comparison with MSSQL to learn about MYSQL (8) -- insert, update, delete, and mssqlmysql
Similarly, it will only explain the difference between SQL Server and SQL Server.
structure without data Method Two actually is also good is a method of the MS SQL self-brought first to have a full backup of the database this is more important than the other is relatively simple Back up the thing log and then in the options to back up the log tail with these 2 things basically OK first restore the complete database Select this do not roll back and then restore the things log Choose the time period when the wrong operation was
SQL CREATE trigger and get the value just inserted
CREATE TRIGGER [t1_test] on [dbo]. [T1]
For insert
As
Begin
declare @cmd sysname, @var sysname
Select @var =ltrim (ID) from inserted
Set @cmd = ' echo ' + @var +
code is as follows:
DELETE From Navtion_TopSubject Where fYopID = 'aaa' (assume that the main category to be deleted is news and the primary key number is aaa)
4. In this way, we can use this aaa to find whether the sub-category table and content table have content.
5. Using the deleted table, the table is logically deleted, which is equivalent to the recycle bin in Windows. SQL
set Class_num=class_num + 1 where class_id= (select class_id fr Om inserted)--test insert into student values (' 0602011 ', ' text ', ' female ', ' 1986-09-21 ', ' 0602 ')--2) created on studentDelete TriggerStu_delete, this trigger updates the Class_nun column in the class table when a record is required to be deleted in the student table. and test the trigger
server| View
View is often used recently, but MSSQL server does not allow the update of view that is more than two base tables associated with it. As a result of the project needs, spent a night to study it. Take some time to record the process and the experience.
Let's look at the authoritative statement:
Updatable views:
Microsoft
Yesterday found in the program data analysis results are not, after the analysis, the original data is still, the value of the field is cumulative. Heart said, not Ah, is to regenerate records before the analysis of AH. Did you forget to delete it? Check the code, found that there are DELETE statements. Then execute in Query Analyzer, error. Try again and again, understand,
Tags: SQL Server tables, views, indexesFirst, the table related1. Create
Use[test] Go setansi_nullson go setquoted_identifieron go CREATETABLE[dbo] . [Ceshi] ([Id][int]notnull, [Name][varchar (]null), CONSTRAINT[PK_Ceshi] primarykeyclustered ([Id]asc) with (Pad_index=off,statistics_ norecompute=off,ignore_dup_key=off,allow_row_locks=on, Allow_page_lo
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.