I need to store questions and answers in a database. The questions will be one to two sentences, but the answers will be long, at least a paragraph, likely more.

The only way I know about to do this right now is an SQL database. However, I don't feel like this is a good solution because as far as I've seen, these databases aren't used for data of this type or size. Is this the correct way to go or is there a better way to store this data? Is there a better way than storing raw strings?

  • Have you looked into Full-text search? en.wikipedia.org/wiki/Full_text_search – FrustratedWithFormsDesigner Mar 23 '12 at 1:24
  • Please define "long" 1k, 5M, 1GB ?? – James Anderson Mar 23 '12 at 1:30
  • why don't you like "raw" strings? Is the data in fact strings, or is it structured data? Do you plan to do something with it that wouldn't work for strings? There isn't any clear reason in your question why a database wouldn't be appropriate. The same with strings (or perhaps CLOBS if they are too big and depending on what database you use). – psr Mar 23 '12 at 1:35
  • I was referring to some clever way of storing them, maybe through some type of compression, not plaintext strings. I'm worried about essentially the size of the database here. – gsingh2011 Mar 23 '12 at 1:46
  • 1
    Which RDBMS are you using? Oracle has some excellent support for handling and searching for text. – Matthew Flynn Mar 23 '12 at 3:49

Mongodb is great, but you know SQL. There is nothing wrong with storing long answers in fields. You can store images or even files in SQL. I think the max field size is 2gb.

I'm almost positive this answer itself is being stored in a table field somewhere.

As for there being thousands of them, no problem. Even millions shouldn't be an issue. You might consider utilizing full text indexing if you're searching the field for keywords or something. But I try not to optimize till I see a problem. Computers are cheap, storage is basically free.

  • 11
    +1 on not optimizing until you actually have the problem! – GrandmasterB Mar 23 '12 at 3:58
  • 4
    The max field size is not specified in ANSI SQL, it depends on the DBMS (and usually a few other factors, such as charset, column data type, storage engine, OS, etc.). – tdammers Mar 23 '12 at 6:42

There is no problem storing long text in databases (SQL or otherwise). Thats how virtually every blog entry (think Wordpress), news article, and forum post (think phpbb) on the internet is stored. I don't know the specific details of stack exchange's setup, but I'm sure your question is stored in a database, too. Most SQL databases have a TEXT field type or the equivalent just for the purpose of storing textual data of any length. Many also have full text searching systems in place.

Make technical decisions based on technical knowledge and understanding, not feelings.


Yes it's the correct way to go. Storing strings in a SQL database is what you want to do. One of my tables in the DB has over a gig of plaintext data and it performs fine.

If you're worried about storage space - remember that it's cheap!

If you're worried about performance - then don't worry, a good database can scale up (or out) to however much data you want to throw in it.

The last thing you want to do is start optimising now for the sake of it (compressing strings before you put them into the DB or something nuts) before it actually becomes a problem. You're just giving yourself more work.


There is no problem storing big strings or binary data. I worked with a database with more than one terabyte of binary data and worked very well (postgres) and the only bad thing was the backup time.

The big question is: "Will you need do constant searches in this text?"

If you are going to search for strings in the text, you can think in one index solution:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.