SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Column Length declaration


Column Length declaration

Author
Message
Arsh
Arsh
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2360 Visits: 878
Dear Experts,
On starting to design for a new project , I would like to know if its better to allocate double the size of the data-length anticipated to grow or to declare a length little more than what is anticipated to grow maximum. Or is it just better to give a much longer length without bothering about anything ? are there any implications of giving too long column lengths with varchar ? Int and Char are understandable though. Thank you in advance.
John Mitchell-245523
John Mitchell-245523
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85756 Visits: 18133
No, just make it the length it needs to be and no more, otherwise you'll get inaccurate memory grants and other such nasties when you start to run queries.

John
Bill Talada
Bill Talada
SSCertifiable
SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)

Group: General Forum Members
Points: 7110 Visits: 2296
Error slightly on the short side. It is safer to loosen rather than tighten constraints in the future - and length is a constraint. Screen and report layout widths are based on defined column lengths. Large column widths will leave a developer bewildered about screen and report designs. Some internal limitations are based on actual and others on declared sizes like little land mines that may eventually blow up.
Thom A
Thom A
SSC-Forever
SSC-Forever (48K reputation)SSC-Forever (48K reputation)SSC-Forever (48K reputation)SSC-Forever (48K reputation)SSC-Forever (48K reputation)SSC-Forever (48K reputation)SSC-Forever (48K reputation)SSC-Forever (48K reputation)

Group: General Forum Members
Points: 48407 Visits: 16163
Like John said, assign it to the size it should be. Databases grow, Tables, grow, but columns should not. You should know how large a field is going to be when you create your database/application. For example, you a reference might be between 8 and 12 characters, so make it a varchar(12); don't make it a varchar(24) incase, one day, just maybe, you *might* have a 13 character reference.

If you're using an IDENTITY column, then choose an appropriate size still. If you know a table isn't going to have more than 10,000 records inserted into in, then you could use a smallint. If you want to really cover yourself create the column as a smallint IDENTITY(-32768,1); you'll have over 64,000 values to play with then.

Queue Joe telling me off for defining a numeric column that I have no plan to do maths on.


Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does :-P

Please always remember to encapsulate your code in IFCode Markup. For example [code=sql] [/code].
Click here to read Jeffs Guide on how to post SQL questions, and get swift and helpful answers from the community
Arsh
Arsh
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2360 Visits: 878
Thanks John , Thom A and Bill .
Thom, your approach seems suitable especially for systems with not-so-high memory if we look from the memory-grant perspective. Since SQL estimates the column data-occupied length to be half, and does the memory grant , what's the magnitude of impact when it knows that the actual grants required are little more because , a varchar(12) has occupancy above 6 (8 to 12) in your example ? I mean is it a costly operation that may impact performance ?

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search