Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server query error

Tags:

sql-server

According to Wikipedia this syntax looks correct...

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'm getting errors. I've tried wrapping the column names in ` but that didn't work either...

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

like image 614
Webnet Avatar asked Mar 27 '12 17:03

Webnet


3 Answers

In SQL Server, string values are delimited by ', not".

Also, column names should either be enclosed in square brackets, or left as they are (if they don't contain spaces).

Your query should, therefore, 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)
like image 84
Cristian Lupascu Avatar answered Oct 09 '22 15:10

Cristian Lupascu


You must use Single quotes instead of double quotes for your values and no quotes at all to specify 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)
like image 45
Francis P Avatar answered Oct 09 '22 15:10

Francis P


The 'Error 207' of sql is related to the incorrect column name of the table. I seems that you are trying to retrieve the data about the column name which doesn't exist in the specified table. I suggest you to make sure that your are using correct column name in you query. Also check the table name is correct mentioned in query or not. Try this and let me know if you are still getting same error or not.

if you are trying to insert values to a Varchar using "" try to use simple ''

like:

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)
like image 35
Gabriel Scavassa Avatar answered Oct 09 '22 16:10

Gabriel Scavassa