Syntax for insert statement

  • I'm just curious about this theoretical situation:  Let's say I've got a table like so...

    CREATE TABLE [dbo].[Transactions] (

     [TransactionID] [int] IDENTITY (1, 1) NOT NULL ,

     [TransactionDateTime] [datetime] NULL ,

    ) ON [PRIMARY]

    With a default...

    ALTER TABLE [dbo].[Transactions] ADD

     CONSTRAINT [DF_Transactions_TransactionDateTime] DEFAULT (getdate()) FOR [TransactionDateTime]

    Question: How would I phrase an Insert statement so that a record is added to the table.  The TransactionID has an identity (that I won't be inserting) and the TransactionDateTime is intended to record the current date/time (which I won't be inserting).

    I know that the table could be changed, or that there are a million other ways of accomplishing what I'm trying to do, blah blah blah...but that's not what I'm after.  Pretending that a trigger on another table fired off an insert to the Transaction table, how would one write the TSQL for that.  I'm wandering if the above can be done at all.

    Thanks

  • insert into transactions default values

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • The special keyword "DEFAULT VALUES" is part of the SQL Standard with usage of:

    Insert into dbo.Transactions DEFAULT VALUES

    SQL = Scarcely Qualifies as a Language

  • You see.  This is why I love this site.  Absolutely brilliant.  Now I know, and can give that answer to someone else when they ask me.  Thanks a million!!

  • Actually it's a great task:

    insert a record without any data in it!

    You assign some automatic values but TO WHAT???

    If you face such task one day just stop and think what are you doing.

    _____________
    Code for TallyGenerator

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

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