-1

I came across a question:

How did you enter the default value for the DateRaised column when you inserted a row?

  1. did not specify a value
  2. specifyed a null value
  3. used a defualt key word

and the answer was 1.

How could I insert the value in this way? Could the answer change or what?

INSERT INTO [DirectMarketing.Opportunity]
(OpportunityID,ProspectID,DateRaised,Likelihood,Rating,EstimatedClosingDate,EstimatedRevenue)
VALUES (1,1,DEFAULT,8,'A','12/12/2020',123000.00)

THANKS A LOT!!!!

Bohemian
  • 412,405
  • 93
  • 575
  • 722
YA_Sql
  • 1
  • Can't make out what the actual question is, but [How to insert default values in SQL table?](https://stackoverflow.com/questions/8777362/how-to-insert-default-values-in-sql-table) might have something to do with it. Or [`insert`](https://learn.microsoft.com/en-us/sql/t-sql/statements/insert-transact-sql?view=sql-server-ver15). (Scroll down to Example D.) And the best practice is to always include a column list in `insert` statements. – HABO Aug 10 '20 at 00:54
  • 1
    the default value for a column is used when no value is supplied, ie the column is omitted, by the insert statement. What is your question exactly? – Bohemian Aug 10 '20 at 01:17
  • Additional suggested reading: [Transact-SQL DEFAULT keyword deprecated? Why?](https://stackoverflow.com/q/39067894/92546) – HABO Aug 26 '20 at 13:49

1 Answers1

2

If you omit the column from the column list and list of values for the insert then the default value for the column will be used:

INSERT INTO [DirectMarketing.Opportunity]
  ( OpportunityID, ProspectID, Likelihood, Rating, EstimatedClosingDate, EstimatedRevenue )
  VALUES ( 1, 1, 8, 'A', '12/12/2020', 123000.00 );
HABO
  • 15,314
  • 5
  • 39
  • 57