SQL Server Query Error

According to Wikipedia, this syntax looks right ...

INSERT INTO dbo.metadata_type ("name", "publishable") VALUES ("Content Owner", 0), ("Content Coordinator", 0), ("Writer", 0), ("Content Type", 0), ("State", 1), ("Business Segment", 0), ("Audience", 0), ("Product Life Cycle Stage", 0), ("Category", 0), ("Template", 0) 

I get errors. I tried wrapping the column names in `, but that didn't work either ...

Error code 207, SQL state 42S22: Invalid column name for Content Owner column.
Error code 207, SQL State 42S22: Invalid column name for Content Coordinator column.
Error code 207, SQL status 42S22: Invalid column name 'Writer'.
Error code 207, SQL status 42S22: Invalid column name "Content Type".
Error code 207, SQL State 42S22: Invalid name for the State column.

+7
source share
4 answers

In SQL Server, string values ​​are limited to ' rather than " .

In addition, column names must be enclosed in square brackets or left as they are (if they do not contain spaces).

Therefore, your request should look like this:

 INSERT INTO dbo.metadata_type (name, publishable) VALUES ('Content Owner', 0), ('Content Coordinator', 0), ('Writer', 0), ('Content Type', 0), ('State', 1), ('Business Segment', 0), ('Audience', 0), ('Product Life Cycle Stage', 0), ('Category', 0), ('Template', 0) 
+12
source

You should use single quotes instead of double quotes for your values ​​and not use quotes at all to indicate which column to insert:

 INSERT INTO dbo.metadata_type (name, publishable) VALUES ('Content Owner', 0), ('Content Coordinator', 0), ('Writer', 0), ('Content Type', 0), ('State', 1), ('Business Segment', 0), ('Audience', 0), ('Product Life Cycle Stage', 0), ('Category', 0), ('Template', 0) 
+3
source

"Error 207" sql is associated with an invalid table column name. It seems you are trying to get data about a column name that does not exist in the specified table. I suggest you make sure that you are using the correct column name in the query. Also check if the table name is specified correctly in the query or not. Try this and let me know if you still get the same error or not.

if you are trying to insert values ​​into Varchar using "try using simple"

as:

 INSERT INTO dbo.metadata_type (name, publishable) VALUES ('Content Owner', 0), ('Content Coordinator', 0), ('Writer', 0), ('Content Type', 0), ('State', 1), ('Business Segment', 0), ('Audience', 0), ('Product Life Cycle Stage', 0), ('Category', 0), ('Template', 0) 
+3
source

If you want to insert multiple lines in one insert statement, here is another way to do this

 INSERT INTO dbo.metadata_type (name, publishable) SELECT 'Content Owner', 0 UNION ALL SELECT 'Content Coordinator', 0 UNION ALL 

etc.

0
source

All Articles