SQL SERVER – Bad Practice of Using Keywords as an Object Name – Avoid Using Keywords as an Object

Madhivanan is SQL Server MVP and very talented SQL expert. Here is one of the nugget he shared on Just Learned.

He shared a tip where there were two interesting point to learn.

  1. Do not use keywords as an object name
  2. [read DHall’s excellent comment below]

He has given excellent example how GO can be executed as stored procedure. Here is the extension of the tip. Create a small table and now just hit EXEC GO; and you will notice that there is row in the table.

Create Stored Procedure

CREATE PROCEDURE GO
AS
SELECT 1 AS NUMBER



Create Table

CREATE TABLE T1 (ID INT)

Now execute following code

INSERT INTO T1(ID)
EXEC GO;

Now when selecting from table it will give us following result:

SELECT *
FROM T1

Now see following resultset:

SQL SERVER - Bad Practice of Using Keywords as an Object Name - Avoid Using Keywords as an Object execgo

So without inserting any data we inserted the data, well indeed good puzzle but very bad practical practice. Every body should be aware of this gotcha and avoid it. Thanks Madhivanan for teaching this interesting learning.

Republishing here with authorization of Just Learned.

Reference: Pinal Dave (https://darkslategrey-bat-805937.hostingersite.com)

SQL Scripts, SQL Stored Procedure
Previous Post
SQL SERVER – Error: Deleting Offline Database and Creating the Same Name
Next Post
SQL SERVER – 2012 RC0: Fix Setup Error: File format is not valid

Related Posts

Leave a Reply