INSERT INTO SET syntax in SQL Server
I come from mySQL to SQL Server. Doesn't the following syntax work in SQ开发者_运维技巧L Server?
INSERT INTO table SET fil1="234", fil2="324"
Is there an comparable statement in SQL Server?
INSERT INTO table (fil1, fil2) VALUES ('234', '324');
The SET
way to insert records is not standard SQL. If you need it to use similar sql's for updates and inserts, you should use Stored-Procedures in MS SQL-Server instead, for example:
CREATE Procedure tableInsertUpdate
(
@ID int,
@fil1 int,
@fil2 int,
@IDOut int OUTPUT
)
AS
IF EXISTS(SELECT ID from table WHERE ID=@ID)
BEGIN
UPDATE table SET
fil1 = @fil1
fil2 = @fil2
WHERE ID=@ID
SET @IDOut=null
END
ELSE
BEGIN
INSERT INTO table
(fil1, fil2)
VALUES
(@fil1, @fil2 )
SET @IDOut=scope_identity()
END
精彩评论