Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Server studio 'script table as' for INSERT to bad syntax

I have a table in a database that looks like this

Database

I want to insert a new record. So I right click on my table, hover over 'script table as' and select the 'INSERT to' option

When I do this, I get this

query

My question is, what is wrong with this syntax? I seem to be getting an error before even trying to add anything. When hovering over the red lines, I get a message saying

'Incorrect syntax near <'

&

'varchar is not a recognized built in function name'

I assumed I would replace the second part with my data values. But I'm not sure.

like image 754
onTheInternet Avatar asked Dec 02 '15 13:12

onTheInternet


People also ask

What is the syntax of insert table?

If you want to add data to your SQL table, then you can use the INSERT statement. Here is the basic syntax for adding rows to your SQL table: INSERT INTO table_name (column1, column2, column3,etc) VALUES (value1, value2, value3, etc); The second line of code is where you will add the values for the rows.

How do I create a insert script in SQL Server Management Studio?

In SSMS Object Explorer, right-click the database. From the right-click menu, go to Tasks >> Generate Scripts... In the Generate and Publish Scripts pop-up window, press Next to choose objects screen. Now, the choose objects screen, choose Select specific database objects and choose the tables you want to script.

How do you script a table with data in SQL Server?

Now right-click the database then Tasks->Generate scripts. After that a window will open. Select the database and always check "script all objects in the selected database". It will generate a script for all the tables, sp, views, functions and anything in that database.

What does script table as do in SQL?

Script tables Use this option to either create the table or drop and create the table. You can also use this option to script the T-SQL associated with modifying the table. An example is to insert into it or update to it.


1 Answers

You need to input actual values.

INSERT INTO tab_name(First_Name, Last_Name, ...)
VALUES ('John', 'Smith', ...);

Replace <col_name, datatype> placeholder with actual data.


You can also Use Templates in SQL Server Management Studio to fill template values.

Query -> Specify Values for Template Parameters

or

Highlight your query and press CTRL+SHIFT+M

like image 104
Lukasz Szozda Avatar answered Nov 02 '22 12:11

Lukasz Szozda