tags:

views:

28

answers:

3

Hi this is my code but when I run it in mysql it will show an error because of datatype but my friend checked it with sql server and it doesn't show error and also insert the value: 32769 .which of them is correct?

CREATE TABLE T1 (A INTEGER NOT NULL);
INSERT T1 VALUES (32768.5);
A: 

Your friend is correct. MySQL converts the number to an integer when inserting it. There is no error.

CREATE TABLE T1 (A INTEGER NOT NULL);
INSERT T1 VALUES (32768.5);
SELECT * FROM T1;

Result:

A
32769

Version information:

SELECT @@VERSION;
'5.1.41-community'
Mark Byers
A: 

an error because of datatype

Col. Shrapnel
+1  A: 

MySQL is (rightly in my view) getting upset because you have supplied a FLOAT value to a column that is expecting an INTEGER.

MS-SQL is performing an implicit conversion behind the scenes, but personally I think this is bad baheaviour - and MySQL's response (the error) is correct...

Martin Milan
I haven't tested this - but something else you might want to think about is the range of the Integer data type...
Martin Milan