question about inserting varchar info (lenght limits?)
Assume I have a table column that accepts a user_id (the column is say varchar 15)
What happens if I send in a variable of length 16?
Is the entered string truncated and accepted by the database? (Assuming no constraints or anything were programmed)Depends on you setting for ANSI_WARNINGS. If on, you get an error message.
This is easy to test:
CREATE TABLE #a(c1 varchar(5))
SET ANSI_WARNINGS OFF
INSERT INTO #a(c1) VALUES('fit')
INSERT INTO #a(c1) VALUES('Doesn''t fit')
SELECT * FROM #a
TRUNCATE TABLE #a
SET ANSI_WARNINGS ON
INSERT INTO #a(c1) VALUES('fit')
INSERT INTO #a(c1) VALUES('Doesn''t fit')
SELECT * FROM #a
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
"david_in_Groton" <anonymous@.discussions.microsoft.com> wrote in message
news:416C3CA9-64CC-4C55-823B-B4A758139F2E@.microsoft.com...
> question about inserting varchar info (lenght limits?)
> Assume I have a table column that accepts a user_id (the column is say
varchar 15)
> What happens if I send in a variable of length 16?
> Is the entered string truncated and accepted by the database? (Assuming no
constraints or anything were programmed)sql
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment