Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert statement with single quote for Integer datatype

I have a table table1 (id integer, Name varchar, Age integer)

While inserting rows into the table I use two statements.

  1. INSERT INTO TABLE1('1','John','33'); and
  2. INSERT INTO TABLE1(1,'John',33);

Both of them work fine. In the first insert statement I have used the value between single quote for the integer datatype as well.

Can I know what can be the difference between both of the statements?

like image 636
user3134614 Avatar asked Oct 11 '25 10:10

user3134614


1 Answers

There is no difference between using single quote for Integer datatype or not.

In first case it will load db server to convert your string literal to integer data type whereas in second case it will directly store integer value to database.

Its good to used without single quote, since that would just be an extra unnecessary step for the database to convert the string literal into a numeric value and also make some little bit difference in performance when there are more records inserted at a time.

like image 170
Yagnesh Agola Avatar answered Oct 14 '25 13:10

Yagnesh Agola