Thread: SQL Variable sizes

  1. #1
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905

    SQL Variable sizes

    I've been wondering what exactly is the benefit of using a TEXT instead of a VARCHAR(10000) variable or something like that?

    If I want to have a limit of 10000 letters, it's best to use a varchar right? Or is it best to use a text as maybe they take up less space?



    --edit--

    hmm, when I set a varchar(15000) in sql it just automatically changes it to TEXT...I guess that answers my question *shrugs*
    Last edited by jverkoey; 01-23-2005 at 02:18 PM.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Well let me phrase your question like this:

    What is better to use:
    Code:
    char foo[10000];
    or
    Code:
    std::string foo;
    Edit: I use varchar when the size is less then 100 or when I know it will be a certain size. If you want to impose a limit you do it through the software prior to inserting it into the table.

  3. #3
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    I was mainly wondering what the overhead of using text is. Because if there isn't any overhead....why not use it all the time? But I don't want to go and use something that either imposes a bad practice or is just not a good idea.

    And yah, I put the software limit in there when the form gets submitted to keep it from extending 10000 characters.

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >>I've been wondering what exactly is the benefit of using a TEXT instead of a VARCHAR

    The benifit of using TEXT is that it takes advantage of one of MySQL's variable length fields. The disadvantage is that TEXT (IIRC) is NOT an ANSI SQL data type, it is specific to MySQL. If you decided to swap to a PostgreSQL or Oracle backend for example, your app might not work.

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    68
    Another benefit would be with TEXT you have the FULLTEXT search capabilities.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to put a check on an extern variable set as flag
    By rebelsoul in forum C Programming
    Replies: 18
    Last Post: 05-25-2009, 03:13 AM
  2. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  3. Problem with embedded SQL in C/C++ (ECPG)
    By NeuralClone in forum C Programming
    Replies: 4
    Last Post: 10-21-2005, 05:16 PM
  4. static class variable vs. global variable
    By nadamson6 in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2005, 03:31 PM
  5. Replies: 2
    Last Post: 04-12-2004, 01:37 AM