Creating tables - int in quotes?
When I create a table and I am putting an int, is this ok:
insert into Employee_T (Emp_Id) values ( '100' /*WILL THERE BE A PROBLEM IF I PUT IT LIKE THIS, IE WITH THE QUOTES*/? )
It is perfectly valid, but entirely unnecessary, to put an integer literal in quotes.
It will be parsed as a string and automatically converted to an integer.
See it working online: sqlfiddle
No problem: the string literal will be CAST to int on insertion.
I wouldn't normally do it myself because it is misleading though...
this should work just fine. The sql server will the parse the string and convert it into a integer. Of course this is not optimal for performance, and it also can cause problems if some formatting like 1.000 or 12,000 is in the string...
No, it's not a problem. I mean, it won't cause an error. Maybe there is just a little performance overhead of converting the types. It's little but unnecessary and may show up on high load.
Quotes are used in case the type is char or varchar. If you are using int then there is no need to give quotes for inserting the values. You should use the following query:-
insert into Employee_T (Emp_Id) values (100);
However, the SQLServer support quotes also for int. But its a good practice if you are not using quotes for int.