How to use reserved words in SQL

Asked

Viewed 446 times

-2

I need to enter a value in the table, but there is a field with the name 'Status', which is a reserved SQL word. How do I use this field in INSERT?

insert into <<tabela>> (status) values ('A')

The error returned is:

There are more columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.
  • 1

    which the SGBD what are you using? And what seems most wrong to me is using <> as a table name.

  • I’m not using <> as a table name, actually I put <<table>, but stackoverflow overwritten. I’m using SQL Server 2016

  • What mistake are you making? The SQL Server allows this column normally.

  • I need to insert a large amount of values into a table, but am getting column amount error in table. There are more Columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of Columns specified in the INSERT statement. Only I’m looking for which field I put the most and I need to know if it’s the Status field, because it turns blue as a reserved word.

  • Your error is not that then. The translation of your error is " There are more columns in the INSERT statement than the values specified in the VALUES clause. The number of values in the VALUES clause should correspond to the number of columns specified in the INSERT statement.". Probably your INSERT is not the one you reported in the question.

  • In Postgresql you should use double quotes (delimited Identifier or quoted Identifier): "status".

  • I need to know if I have to use something like double quotes in SQL Server in reserved words when I put as field name.

  • Read my comment. Your error has nothing to do with the column status.

  • I know the problem is the amount of values, but the word status in the bank is as reserved, should not be of the ANSI standard. I want to know if you have something like quotes to use in reserved words in case you name fields, to see if this can be the problem (do not identify the word status as field, so do not identify the value I am entering in this field).

Show 4 more comments

2 answers

0

At first the word STATUS is not a reserved word of SQL Server as you can see in reserved keywords list.

I tested in the db<>fiddle and your example (without <<>>) works normally.

By your mistake the problem is not with the column STATUS and yes with the fact that you have put more columns in the INSERT than in the clause VALUES. Your error, in free translation, is as follows:

Existem mais colunas na instrução INSERT do que os valores especificados na cláusula VALUES. O número de valores na cláusula VALUES deve corresponder ao número de colunas especificadas na instrução INSERT.

-1


In Sqlserver, when I use reserved words as field name in the table, I need to put SQL pro quotes recognize as field. In this case, the reserved word I was using was Status (sql was recognizing as reserved word), but this word is not part of the ANSI standard.

  • Your answer is incorrect. As I have shown below it is possible yes to use the word status

Browser other questions tagged

You are not signed in. Login or sign up in order to post.