Read about sql server update table from another table, The latest news, videos, and discussion topics about sql server update table from another table from alibabacloud.com
A) Easy to type, update efficiency:Update table1Set Field1=table2.field1,field2=table2.field2From Table2 where table1.id=table2.idb) Conventional way, this is equivalent to a left join, in the outside where is the number of updates, if not add where is all recordsUpdate table1 Set field1=(select top 1 field1 from table2 where table2.id=table1.id)where table1.id in (condition)SQL
Original: Oracle\ms SQL Server Update Multiple Table association updateA single update UPDATE statement is not able to update multiple tables unless you use triggers to suppress updates
I tried multiple times and finally concluded that when multiple SQL Server tables are associated with update, an as Alias cannot be added to an external table, and a syntax error is returned.Only the table name can be written as the prefix for reference and cannot be referen
Copy Code code as follows:
Create Trigger Tr_mastertable_update
On mastertable
After update
As
If update ([Type])--triggers this trigger when the Type field is updated
INSERT INTO masterlogtable
Select
Id
, (case [Type] when 1 Then ' Type1 '
When 2 Then ' Type2 '
When 3 Then ' Type3 '
When 4 Then ' Type4 '
Else ' Typedefault '
End
, Name
From inserted
Go
Add another: Insert and
SQL Server uses triggers to update multi-table views.
The procedure is to use the update trigger to generate two virtual tables "inserted" to store the modified data information and the "deleted" table, then,
join [DBO]. ZHONGHE_TAB as z on f. Student ID = Z. Student ID8 order by f. Student ID ASC9 GO10. View the created view:3.2.1. Modify the information of multiple data tables through the view ???? :1 UPDATE [SQL-LI]. [dbo]. [SHITU_FFENSHU_XINXI]2 SET [name] = 'aaaaa', -- this field is in the [information table]3 [average score] = 111 -- this field is in [s
Label:One, MS SQL Server Multi-Table Association updateSQL Server provides the FROM clause of the update, which connects the table that will be updated to its data source. Although only one ta
Tags: div LSE blog Information upd ROM targe com serveTransferred from: http://www.maomao365.com/?p=6973 Summary:In SQL scripting, if you need to use the method of table aliases in update Delete, you must write according to certain rules, otherwise the corresponding exception information will appear as follows:Lab environment:
Tags: process _id update create STS Delete field name stored procedureTransferred from: http://www.maomao365.com/?p=5277Summary:Here's how to add a new field to a table in the "on-line system".
System deployment scripts, adding columns to the method:In system script publishing, how to modify and add a stored procedure custom function view, we usually use the following steps to write such a script1 Det
Tags: ring using har cell storage traints Batch ref ACERecently modified the database table structure, the data synchronization problem, found that a lot of data has been modified, but filtered through the view or the original data, so suspect should be the view cache data, in the garden to find the following blog post, here to make a record memo. original link:http://www.cnblogs.com/yashen/archive/2004/12/23/81000.html This is often the case when w
Copy codeThe Code is as follows:Create trigger TR_MasterTable_UpdateOn MasterTableAfter updateAsIf update ([Type]) -- this trigger is triggered only when the Type field is updated.Insert into MasterLogTableSelectId, (Case [Type] when 1 then 'type1'When 2 then 'type2'When 3 then 'type3'When 4 then 'type4'Else 'typedefault'End), NameFrom insertedGo In addition, the insert and update data are stored in the tem
At work, we often need to store information greater than 8 KB to the Text, ntext, and image fields of tables in the database. During data maintenance, in this case, you may save the storage information in one location to another.
When the data size is smaller than 8 K, we can use the following methodNote that the table structure used in the following example is as follows:Photos table nameField data typePho
CopyCodeThe Code is as follows: Create trigger tr_mastertable_update
On mastertable
After update
As
If Update ([type]) -- this trigger is triggered only when the type field is updated.
Insert into masterlogtable
Select
ID
, (Case [type] When 1 then 'type1'
When 2 then 'type2'
When 3 then 'type3'
When 4 then 'type4'
Else 'typedefault'
End)
, Name
From inserted
Go
In addition, the insert and
UpdateTime by field in the table, numbered every day, numbered from 1, with the table's primary key CID, and storing the data in a temporary tableWith temp as(SELECT Cid,updatetime,Row_number () over (PARTITION by CONVERT (varchar), updatetime, and order by UpdateTime) as Row_numFrom Customer_transfer)Update Batchno from the temporary table according to the prima
Tags: io for ar art CTI on EF C SQLIn SQL Server, trigger, INSERT, UPDATE, delete state:CREATE TRIGGER t_inms_alarmsOn [PHS]. [dbo]. [Alarmcurrent]For INSERT, DELETEAsDECLARE @rows intSELECT @rows = @ @rowcountIF @rows = 0Return--If the table is inserted, synchronize the update
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, Delete from does not recognize table name alias! Thinking back, the original p
Assume that we have two tables. One Table stores Product information for the Product table, with the Product Price column Price. The other table is the ProductPrice table, update the Price field in the ProductPrice table to 80% of
A SQL Server operation, such asThere is no problem with this.Two MySQL operations such asBut in MySQL I wanted to implement this function, but it went wrong.It turns out that MySQL does not support sub-queriesWe can make this change so we can do it.See no, I just add a layer in the query outside, but realized.The code is as follows:Create PROCEDURETESTP (inch_idint)begin --Set @tt = (select id from UserA w
SQL Update multi-table joint Update method, sqlupdate joint Update
Sometimes we need to update the data in multiple tables at the same time, then we need to use the following method:
(1) sqlite multi-
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.