SQL 2008 Datatype-Length Help needed

  • Please help me out on the data types and length- I have to create the sql table and the columns and data are listed below. I am not sure about the datatype and length. Can you please help me?

    ColumnNameData

    Milstone_NumberMilestone #1

    S_Objective1. A Nat System Must Be band at the Community Level

    Project_NameA. Develop Protect-Prep Comm

    Project_Item1.1.A

  • It depends on your business requirements, not on what someone else might think based on a very, very small data sample.

    They all look like strings so a varchar would be as good as any, as for length well, who knows? Anywhere from 5 to 65.

  • The data is sample is in bracket (Milestone #1), (1. A Nat System Must Be band at the Community Level)

    (A. Develop Protect-Prep Comm), (1.1.A ) and you are saying varchar??

  • What data types are you planning on inserting into the table? If you know that, you should be able to answer your own question 🙂

    If you're allowing users to input free type, what is the maximum length of the field they're inputting data into?

    Varchar seems like the way forward, but if you can't be certain of the data going in (and this table isn't going to extend to a billion rows!), I'd recommend making it as wide as possible.

    _____________________________________________________________________
    Disclaimer - The opinions expressed by the mouth are not necessarily those of the brain

  • hydbadrose (9/20/2011)


    The data is sample is in bracket (Milestone #1), (1. A Nat System Must Be band at the Community Level)

    (A. Develop Protect-Prep Comm), (1.1.A ) and you are saying varchar??

    Yes, I can see the data. The problem is this is a very small sample dataset (unless you only going to insert one record into your table).

    Yes, varchar would be a valid type. But from your sample data there is no way to tell what suitable lengths for the columns might be. Only proper analysis will tell you that, we cannot guess!

  • Given your sample this will tell you your column widths: 🙂

    SELECT LEN('A Nat System Must Be band at the Community Level'),

    LEN('Milestone #1'),

    LEN('A. Develop Protect-Prep Comm'),

    LEN('1.1.A')

    :w00t:

  • For Project_Item 1.1.A I was thinking to use float.

  • hydbadrose (9/20/2011)


    For Project_Item 1.1.A I was thinking to use float.

    [1.1.A]

    it has two periods and the letter "A" in it...it would have to be a varchar.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • hydbadrose (9/20/2011)


    For Project_Item 1.1.A I was thinking to use float.

    But '1.1.A' is not a valid float its got an 'A' in it. Since when was 'A' a valid digit?

  • Thanks!

  • When in doubt you should consult the datatypes and what they can handle. http://msdn.microsoft.com/en-us/library/ms187752.aspx

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply