Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

INSERT INTO SET syntax in SQL Server

Tags:

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?

like image 438
Alexander Molodih Avatar asked Aug 07 '11 15:08

Alexander Molodih


People also ask

Can we use set in insert query?

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.

What is the syntax of insert into?

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);

Can we use insert statement in function in SQL Server?

No, you cannot. From SQL Server Books Online: User-defined functions cannot be used to perform actions that modify the database state.

How do I insert data into a specific column in SQL?

INSERT INTO Syntax Specify both the column names and the values to be inserted: INSERT INTO table_name (column1, column2, column3, ...)


2 Answers

INSERT INTO table (fil1, fil2) VALUES ('234', '324');
like image 180
JK. Avatar answered Sep 19 '22 16:09

JK.


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 
like image 34
Tim Schmelter Avatar answered Sep 18 '22 16:09

Tim Schmelter