New to SQL. Need help

  • Hi I have to create a table with the following

    Accountnumber,DOB,FullName,Accountopendate,currentbalance

    I am having troubles:

    What data type should I use for DOB?

    How do I get Account open date automatically generated?

    And how do I get the balance displayed?

    Can some one please help with the syntax???

    Also, the account number is 5 digits and incremental.

    Would appreciate your help.

    Thanks

  • OwnSQL (1/10/2015)


    Hi I have to create a table with the following

    Accountnumber,DOB,FullName,Accountopendate,currentbalance

    I am having troubles:

    What data type should I use for DOB?

    Use the DATE datatype, unless you're anticipating doing some "per minute" date math in which case you should use DATETIME unless someone is tasking you to write "truly portable code" (heh... which is truly a myth) where you should use DATETIME2.

    How do I get Account open date automatically generated?

    Add a default to the table that uses GETDATE() or CURRENT_TIMESTAMP.

    And how do I get the balance displayed?

    There has to be another table that has the transactions in it before this can be done.

    Can some one please help with the syntax???

    Yes, but this really seems like homework or a class assignment. Lookup CREATE TABLE for SQL Server on Google and give it a try on your own.

    Also, the account number is 5 digits and incremental.

    Lookup IDENTITY column on Google.

    Would appreciate your help.

    Understood. I'm trying to help you become a bit self sufficient on these things.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Thanks a lot Jeff. This is my first post and I am glad you replied.

  • The question now is, do you understand? After checking out Google on some of the things I suggested and if you're still having problems, c'mon back and post what you've tried so we can help.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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