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)
 Same Basic.

Author  Topic 

kfkenneth2001
Starting Member

12 Posts

Posted - 2005-05-18 : 00:37:33
Just want to know the fact of some basic that never mentioned on my books.
When someone define the size of fields(say nvarchar(50)) in a table, he will never know whether a user need to fill in text of 51 letters. If, for safty, I change the size to 100, would the database reserve double space? Would more reserved space make the whole thing run slower?
Thx.

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-05-18 : 01:06:08
Generally, these things happen when business requirements and/or the application was not designed well. You need to make sure if you have an database field which only takes 50 characters that:

1. The application will not take anything greater than 50 characters.
2. The business doesn't need anything bigger than 50 characters.
3. You have an appropriate error given to the user if they try to enter more than 50 characters.

If the datatype is CHAR or NCHAR, it would store twice the space by doubling the size of the field. It will not double the space size if you use VARCHAR or NVARCHAR unless you actually fill it; however, you still should not design a database this way. Don't store more data than you need. Don't design mistakes into the system. Also, each row has a maximum length. It's a very common mistake to have a bunch of these variable fields. It will work great until the combined row size of any given row exceeds the maximum. Then you start understanding really quickly why you should not have done it.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

kfkenneth2001
Starting Member

12 Posts

Posted - 2005-05-19 : 03:05:17
"each row has a maximum length" - what do you means by "each row"?
Thx.
Go to Top of Page

raclede
Posting Yak Master

180 Posts

Posted - 2005-05-19 : 04:35:36
I think what he mean is each column.. each datatype per column has a maximum size,
e.g.
varchar datatype - 8000 max length
nvarchar datatype - 4000 max length

also you should know the use of different data types on how and when it will be use, lets
take for example the data type above. Varchar is use for ordinary characters but when you are using special characters like chinese, thai, and others double byte characters nvarchar should be used instead.

Cursors are for those who doesn't know how to use SQL

raclede™
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-05-19 : 20:39:08
I meant each row. Look up "maximum capacity specifications" in Books Online.


MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

kfkenneth2001
Starting Member

12 Posts

Posted - 2005-05-20 : 00:13:42
Thank you again :)
Go to Top of Page
   

- Advertisement -