i.e. if I create a VARCHAR(50) field, what happens if I try to assign it a value that's 100 characters long?
Will SQL Server let me do this? Is it somehow less efficient?
If you try forcing a large string into a smaller-size variable, the incoming string will be simply chopped off at the appropriate size.
declare @Variable varchar (50)
set @Variable = replace (SPACE (100), ' ' , '.')
print @Variable
the output is 50 characters long
..................................................
If you try to force a large string into a small sized Field in a Table, an Error will be raised
declare @MyTable Table
(
TestVariable varchar (50)
)
insert into @MyTable (TestVariable) select replace (SPACE (100), ' ' , '.')
select * from @MyTable
the output is
Msg 8152, Level 16, State 14, Line 6
String or binary data would be truncated.
The statement has been terminated.
TestVariable
------------------------------------------------
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With