-2

I want to insert following info in the table but it is giving me following error from the following code:

Msg 109, Level 15, State 1, Line 1 There are more columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.

create table registration
(
id  int identity primary key,
first_name varchar(100),
last_name varchar(100),
username varchar(100),
[password] varchar(100),
email varchar(100),
[address] varchar(100),
gender varchar(10),
dob date,
reg_date date,
country varchar(50),
city varchar(50),
[status] bit
)
select * from registration

insert into registration (first_name,last_name,username,password,email,[address],gender,dob,reg_date,country,city,status) 
values ('Ali','Khan','alik','123','alikhan@gmail.com','Male','19930318','20170318','Pakistan','Karachi')
James Z
  • 12,209
  • 10
  • 24
  • 44
Burhan Ahmed
  • 1
  • 1
  • 4
  • 3
    The error message is telling you exactly what you need to know. Your insert statement contains 12 columns and your VALUES clause contains 10 values. – Peter Feb 17 '17 at 18:11

3 Answers3

1

The error is pretty clear, you are missing some of the columns in the values. Try this:

insert into registration (first_name,last_name,username,password,email,[address],gender,dob,reg_date,country,city,status) 
values ('Ali','Khan','alik','123','alikhan@gmail.com','100 Sample Street Address', 'Male','19930318','20170318','Pakistan','Karachi', cast(1 as bit))
Anand
  • 1,165
  • 10
  • 18
0

Look at your query like this:

Column        Value you want to insert
-----------   ------------------------
first_name    'Ali'
last_name     'Khan'
username      'alik'
password      '123'
email         'alikhan@gmail.com'
[address]     'Male'
gender        '19930318'
dob           '20170318'
reg_date      'Pakistan'
country       'Karachi'
city
status

You are missing a few values. The error clearly says that.

Josh Part
  • 2,154
  • 12
  • 15
0

The values specified in the values clause and the insert statement are equal in numbers. That's where my problem is