Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello ,

i have one small question i know solution but dont know why it happens

i was developing one project before i have named my column name as

SQL
get int allow null


now when i use stored procedure to insert update data in get then working very good but when i update my record directly from table like this

SQL
get buy 
 0   1
when i change this 0 to 1 there is error


error converting varchar value 'get' to datatype int

now when i change the get to gett it works fine but i dont know why we can not use system words of sql??
any suggestoins??
Posted

Strictly speaking its better not to use the keywords which has the inbuilt features or fuctions. Look for alternative words with similar meaning. But in rare case if you still want to go with the keywords then surround them usign sqare brackets '[]' for ex. in your case [get]. So that the parser understand it as a normal word rather than inbuild keyword.
 
Share this answer
 
Comments
Dholakiya Ankit 13-Aug-13 2:35am    
ok but if i use as [get] then in sp also i have to use like
insert into [get] values 1 right?
ArunRajendra 13-Aug-13 2:43am    
Yes some it also depends on the keyword. I tried this code in 2008 it works even for get and int. But it is always advisable to use []. I am not sure if there is settings which can be used to enable / disable this feature by admin.

<pre lang="sql">declare @t table
(
get int
)

declare @t1 table
(
int int
)

insert into @t(get) values (1)
insert into @t(int) values (1)</pre>
Quote:
Microsoft SQL Server uses reserved keywords for defining, manipulating, and accessing databases. Reserved keywords are part of the grammar of the Transact-SQL language that is used by SQL Server to parse and understand Transact-SQL statements and batches. Although it is syntactically possible to use SQL Server reserved keywords as identifiers and object names in Transact-SQL scripts, you can do this only by using delimited identifiers.


Source: Reserved Keywords (Transact-SQL)[^]
 
Share this answer
 
Comments
Dholakiya Ankit 13-Aug-13 3:06am    
thanks maciej 5ed from me
Maciej Los 13-Aug-13 3:07am    
You're welcome ;)
... and thank you ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900