Getting Error while insert the data into table when the column as DEFAULT Constraint on Datetime data type and Insert the

Ramana Kopparapu 306 Reputation points
2023-03-21T01:33:35.3+00:00

I have create EMP table to insert the data with three columns. I am getting the below error while inserting the data.

Msg 213, Level 16, State 1, Line 6

Column name or number of supplied values does not match table definition.

Could anyone please help me to resolve the issue?

CREATE TABLE EMP ( id int IDENTITY(1,1),Name VARCHAR(10),
    JoiningDate DATETIME
);

ALTER TABLE EMP
ADD CONSTRAINT df_Joindate DEFAULT (getdate())FOR JoiningDate

SQL Server Other
0 comments No comments
{count} votes

Accepted answer
  1. LiHongMSFT-4306 31,566 Reputation points
    2023-03-21T02:48:22.31+00:00

    Hi @Ramana Kopparapu

    Column name or number of supplied values does not match table definition.

    You're getting this error because the number or name of the columns you're trying to insert data into doesn't match the table definition.

    Could you please post your INSERT statement as well? Cause I tested on my side with below code and worked fine.

    insert into EMP(Name)
    values ('aaaa'),('ccc'),('fff'),('eee')
    

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Olaf Helper 47,436 Reputation points
    2023-03-21T07:19:58.8733333+00:00

    Column name or number of supplied values does not match table definition.

    The error message has nothing to do with the constraint.

    As the message clearly says, the colmuns in the INSERT statement must match with the column values you want to insert.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.