时间:2014-10-17 09:52:15 来源: 复制分享
以前不怎使用mysql,最近有些事情,需要用到php和mysql。目前使用的版本是5.5.1
mysqlsql server有很多不同。可能逐地整理一些文出大家考。
今天第一篇,update操作的差。在mysql中,如果update句要置的新值,中前的值是一的,其意味着需更改。操作是不被行的。
什呢?因我在php程序中,需要取update句所影的行。我很多候0. 追查下去,才明白他是做的。下中可以看到,我行update句次,第一次是修改了的(Changed:1),而第二次有修改(Changed:0)。
而查php的助文,也很清楚地定了行
http://php.net/manual/en/function.mysql-affected-rows.php
Returns the number of affected rows on success, and -1 if the last query failed.
If the last query was a DELETE query with no WHERE clause, all of the records will have been deleted from the table but this function will return zero with MySQL versions prior to 4.1.2.
When using UPDATE, MySQL will not update columns where the new value is the same as the old value. This creates the possibility thatmysql_affected_rows() may not actually equal the number of rows matched, only the number of rows that were literally affected by the query.
The REPLACE statement first deletes the record with the same primary key and then inserts the new record. This function returns the number of deleted records plus the number of inserted records.
同的句,在sql server中就不是。例如下面,其句是一模一的,但每都被行,一行被更改
了明一,我可以一器一下
CREATE TRIGGER TestTrigger ON employees FOR UPDATE AS BEGIN DECLARE @id INT DECLARE @name NVARCHAR(50) SELECT @id=UID,@name=Name FROM DELETED PRINT @id PRINT @name END
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }
再次行句,我可以看到如下果
明什?明sql server的update句每次都行,不管值是否有必要行化。
在sql server中,update操作有步,首先行delete操作,然後行insert操作。
上面的器代中,的deleted表,是一表,面保存的就是delete的,也就是我常所的“值”