Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Table Field Length

Author  Topic 

hasanali00
Posting Yak Master

207 Posts

Posted - 2004-11-05 : 07:01:56
How important is the 'Length' of a table field.

Does it mean that this field cannot contain data more than the lenght of this field.

What happens, if I try to insert data into this field which is more than the length.

When designing a table, does it matter if I create large field lengths. e.g does it affect performace...etc

kind regards

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2004-11-05 : 07:22:39
in short.

1. very
2. yes
3. chop off and discard the extra data
4. it can....unused space still has to be traversed to get to populated data....it also costs money.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-11-05 : 07:59:58
Errrmmm ... I think 3 is error "String or binary data would be truncated"

4 if varchar then there is no wasted space is there?

Kristen
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-11-05 : 08:08:24
If you get "String or binary data would be truncated" then the row is not inserted. A multi-row operation would fail and no rows would be inserted:

create table #duh(a varchar(4) not null)
insert #duh
select '123' union all
select '1234' union all
select '12345'
select * from #duh
drop table #duh


Varchar won't store more data than the length of the value, but it may still "waste" some space. If you update a varchar column from 1000 bytes to 500, that now-empty space will not be reclaimed or reused on the data page unless the table was reindexed (even then it may not be reused)
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-11-05 : 08:33:04
"update a varchar column from 1000 bytes to 500"

Good point, hadn't thought of that.

Kristen
Go to Top of Page

hasanali00
Posting Yak Master

207 Posts

Posted - 2004-11-05 : 08:56:45
Any difference between nvarchar & charvar.

I always tend to use nvarchar
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2004-11-05 : 09:22:05
the 'n' versions are only worthwhile/needed if you have some form of internationalisation to worry about, particularly support for asian and/or arabic character sets.

otherwise for plain old english data, you would double the size of the dataspace compared to the 'non-n' versions of the columns.
Go to Top of Page
   

- Advertisement -