On 18-4-2014 18:56, Simon Slavin wrote:
On 18 Apr 2014, at 5:28pm, Dominique Devienne <ddevie...@gmail.com> wrote:
I'm not sure where you get that declaring a column as varchar()
implicitly truncate
While I can't find any reference one way or another in a SQL standard, all
implementations I've seen that understand VARCHAR(n) truncate for any column
defined with a number inside the brackets:
<http://msdn.microsoft.com/en-us/library/ms176089.aspx>
"When character expressions are converted to a character data type of a different
size, values that are too long for the new data type are truncated."
<https://dev.mysql.com/doc/refman/5.0/en/char.html>
"If strict SQL mode is not enabled and you assign a value to a CHAR or VARCHAR
column that exceeds the column's maximum length, the value is truncated to fit and a
warning is generated."
('warnings' in MySQL are not an indication of failure and are routinely
ignored.)
SQLite is unusual in that it ignores the number in the brackets. I don't know
what various implementations do for just VARCHAR or for VARCHAR() with no
number inside the brackets.
Simon.
1> select @@version
2> go
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
Dec 28 2012 20:23:12
Copyright (c) Microsoft Corporation
Express Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601:
Service Pack 1)
(1 rows affected)
1> create table test (a varchar(4));
2> go
1> insert into test values('abcd');
2> insert into test values('ABCDE');
3> go
(1 rows affected)
Msg 8152, Level 16, State 14, Server ACER\MSSQL, Line 2
String or binary data would be truncated.
The statement has been terminated.
1> select * from test;
2> go
a
----
abcd
(1 rows affected)
1>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users