store datatype

  • hi

    i need to store number(2) data type in sql.what should i use ,if i use numeric(2)

    give sme error.i can use int.

    but i want something which has 2 number only allowed

  • you're missing the scale (the number of digits after the decimal point)

    Numeric(2,0)

    ---------------------------------------------------------------
    Mike Hahn - MCSomething someday:-)
    Right way to ask for help!!
    http://www.sqlservercentral.com/articles/Best+Practices/61537/
    I post so I can see my avatar :hehe:
    I want a personal webpage 😎
    I want to win the lotto 😀
    I want a gf like Tiffa :w00t: Oh wait I'm married!:-D

  • When considering datatypes, its important to remember that smaller is usually better. Using a numeric (2,0) datatype requires 5 bytes to store. Using an INT datatype would require only 4, and a TINYINT would require only 1 byte. You can add a check constraint to only allow values up to 99 like so.

    create table #example (data tinyint)

    ALTER TABLE #example

    ADD CONSTRAINT chkDataColumnGreaterThan99 CHECK (data <= 99 );

    insert into #example

    select null

    insert into #example

    select 0

    insert into #example

    select 99

    insert into #example

    select 100 -- will throw an error

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills

Viewing 3 posts - 1 through 2 (of 2 total)

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