I come from mySQL to SQL Server. Doesn't the following syntax work in SQL Server?
INSERT INTO table SET fil1="234", fil2="324"
Is there an comparable statement in SQL Server?
MySQL INSERT used to insert a specific valueTo insert values into the columns, we can use the SET clause instead of the VALUES clause. INSERT INTO Customers SET ID=2, FirstName='User2'; In the output, the statement inserts values into the columns based on the explicitly specified values in the SET clause.
There are two basic syntax of INSERT INTO statement is as follows: INSERT INTO TABLE_NAME (column1, column2, column3,... columnN)] VALUES (value1, value2, value3,... valueN);
No, you cannot. From SQL Server Books Online: User-defined functions cannot be used to perform actions that modify the database state.
INSERT INTO Syntax Specify both the column names and the values to be inserted: INSERT INTO table_name (column1, column2, column3, ...)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With