Problem with default date column

  • Hi all,
    I am getting an error while running code below on MSSql 2008R2. What am I missing???


    IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.B') AND type in (N'U'))
    Drop table B;

    create table B (
    acct_id int,
    entity varchar(30),
    first_name varchar(30),
    last_name varchar(30),
    email varchar(30),
    created_date datetime not null default getdate()
    )

    insert into b values (1, 'a', 'e', 'p', 'ep@c.com')


    Msg 213, Level 16, State 1, Line 1
    Column name or number of supplied values does not match table definition.

  • your table has 6 columns in it, but your INSERT statement only has 5 columns.  If you don't specify a value for all 6 columns, you have to explicitly specify the columns like this:

    insert into b
        (acct_id, entity, first_name, last_name, email)
    values
        (1, 'a', 'e', 'p', 'ep@c.com')

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

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