user1789573
user1789573

Reputation: 535

SQL insert into statement gone wrong

Okay, so i have looked up basic examples of the INSERT INTO for SQL Server Management Studio 2014 and they are fairly straight forward. However, i'm getting an "Incorrect syntax near..." error and i have no idea why.

For example, if i have database MyDatabase with a dbo schema and a table named MyTable with an integer column named MyColumn and i wanted to insert a value of 1 i would make an INSERT INTO statement like this:

INSERT INTO [MyDatabase].[dbo].[MyTable] (MyColumn, INT) VALUES (1)

However, it gives me the following error: "Incorrect syntax near 'MyColumn'" and i am not sure what i'm supposed to do to get this to work. Any advice would be greatly appreciated!

Upvotes: 1

Views: 1207

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726479

Syntax of the column list for INSERT INTO uses column names without column types. Column types are specified when you create your schema; when you are doing an insert, RDBMS does not need you to specify the column type, because it already knows it.

This should work:

INSERT INTO [MyDatabase].[dbo].[MyTable] (MyColumn) VALUES (1)

Upvotes: 1

Related Questions