views:

134

answers:

8

I am doing my first database project.

I would like to know what is an appropriate limit for questions in length.

My plan has varchar(5000) for the length of a question at the moment.

What is the appropriate limit for a question in a database?

[edit]

A question in the database is like a question here in SO, with code formatting.

+3  A: 

Which DBMS are you using? You'll probably want to use a TEXT column or equivalent, which is much better for storing large amounts of data.

Stefan Mai
We have little information, but whatever is meant by "question," I do not think a text entry is the subject.
Smandoli
Provided these questions can be fairly long (if you'll notice, some StackOverflow questions are well into the thousands of characters), I don't think that text is out of the question. Ha.
Stefan Mai
+2  A: 

Can the questions be quite long? Perhaps varchar(max) would be the best choice. (This is assuming that you are using SQL Server of course.)

Andrew Hare
A: 

A question or an answer?

Also, appropriateness is completely dependent on the application domain. By this, I mean that if you are doing simple survey's, then the question will probably be less than 500 characters.

Assuming you are building this off of some specs, what does the form look like?

Chris Lively
I'm building a discussion site inspired by SO.
Masi
A: 

If there truly is no limit, you can use a CLOB (or your local database's equivalent) which allows unlimited text.

Adam Batkin
I wonder how safe that would be in practice, or is it better practice to limit the size before getting to the db?
CookieOfFortune
+1  A: 

You can set your own limit if you are also designing the app for question input. For example think of Twitter's limit to 140 characters or less. You could do the same thing here.

Jeremy Cron
+1  A: 

As the other answers say, this is not a database question but an application question? How big do you need the field to be to store your questions?

However, the one thing that's almost certainly a bad idea is using VARCHAR for things like questions which contain natural text. This only supports the basic US-ASCII character set which is very likely not what you want. I'd suggest you use NVARCHAR instead which supports the full range of international characters.

If you need a short field (say a few hundred characters at most) then it would be reasonable to use a field with a specified maximum length, e.g. NVARCHAR(256), however if it's a lot of text (as can appear on this site) then NVARCHAR(MAX) is probably more appropriate. Note that in later versions of SQL Server, the NTEXT type is essentially deprecated.

Greg Beech
Thank you for pointing out NVARCHAR!
Masi
IIRC, the maximum length for nvarchar(max) in SQL Server 2005 would be 4000 characters.
kevinw
@kevinw - Um, no, the maximum length for NVARCHAR(MAX) is about 1,000,000,000 characters as the max field size is 2GB and it uses 2 bytes per character.
Greg Beech
@Greg Beech - apologies - my figure is for nvarchar rather than nvarchar(max) (remembering the number comes from too much time ensuring a database schema would still work in 2000).
kevinw
+3  A: 

nvarchar(max) sql server 2005

astander
A: 

Some of your other questions indicate that you are using PostgreSQL. If you are, then the PostgreSQL documentation on data types has a good discussion of the different types available and when it is appropriate to use each. In particular, note that "nvarchar" is not the name of a PostgreSQL data type.

Greg Hewgill