In this post, we’re going to talk about using reserved keywords as column names. This is very similar to the previous “IMPALA – Reserved Keywords As Columns” article, but we will see how it can be implemented in SQL Server this time. It is not best practice to use the reserved keywords for tables and columns, as mentioned in the previous article. Yet one must know how to execute it in the case of condition demands.
In Impala, an error is returned when choosing the columns that are currently reserved keywords in Impala. This is because the tables were built in Hive with the keywords reserved in Impala. We have to use the “`” (escape) symbol for these columns. Similarly, in SQL Server, we would use the name of the column in the “[” and “]” (square brackets a.k.a. box brackets).
Let’s check it out.
CREATE TABLE ReservedWords([Select] INT, [Update] INT,[Delete] INT, [Insert] INT);
INSERT INTO ReservedWords VALUES (170,20,3,60)
INSERT INTO ReservedWords VALUES (120,15,5,70)
INSERT INTO ReservedWords VALUES (110,17,2,80)
INSERT INTO ReservedWords VALUES (140,12,1,90)
SELECT * FROM ReservedWords
OR you can use-
SELECT [select], [insert], [update], [delete] FROM ReservedWords
The same is applicable to the table names. Look at the below example.
CREATE TABLE [select] ([int] INT);
INSERT INTO [select] VALUES (10),(20),(30)
SELECT [int] FROM [select]
Hope you find this article helpful.