What is mss开发者_StackOverflow社区ql function that have similar with mysql_db_query()?
and what about mysql_insert_id()?
Look at the PHP Mssql documentation. The functions you're looking for are mssql_query()
and the following:
<?php
function mssql_insert_id() {
$id = 0;
$res = mssql_query("SELECT @@identity AS id");
if ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
$id = $row["id"];
}
return $id;
}
?>
I think the closest you will come to this in T-SQL is the following:
Use <MyDatabase>
Exec ('Select <ColumnList> From <SomeTable>')
In MSSQL, you can use the SCOPE_IDENTITY() function to get the last ID created by the given connection, in the same scope. Put them both together so you get the ID back just after row creation.
INSERT INTO myTable (field1,field2) VALUES(val1,val2); SELECT SCOPE_IDENTITY() AS myId;
Note, you could also use @@IDENTITY, but that returns the last ID created, regardless of scope, so if you inserted a new row, and a trigger/stored procedure fired and inserted something into another table, @@IDENTITY would return that ID.
精彩评论