Reputation: 43
Schedule table has five columns gameday,oppoent,scoredifference,score,opponent score . scoredifference is generated column. I m trying to insert into schedule table, its giving me error#1136;
insert into schedule values('2017-02-01','atlanta falcons',14,7);
Upvotes: 1
Views: 123
Reputation: 1044
Your column doesn't match with your table. And it is a bad haabit to use insert query. Just Checkout this :
1. Use Column Name Before Values You Want To Insert
insert into schedule(date,city,t1,t2) values ('2017-02-01','atlanta falcons',14,7);
2. Match The Column Properly. But This is Not The Proper Way to Insert.
insert into schedule values ('','2017-02-01','atlanta falcons',14,7);
Upvotes: 0
Reputation: 182
I think ScoreDifference is not primary key therefore not auto increment. You can use this;
CREATE TABLE [dbo].[Schedule](
[Scoredifference] [int] IDENTITY(1,1) NOT NULL,
[Gameday] [datetime] NULL,
[Oppoent] [nvarchar](50) NULL,
[Score] [int] NULL,
[OpponentScore] [nchar](10) NULL,
CONSTRAINT [PK_Schedule] PRIMARY KEY CLUSTERED
(
[Scoredifference] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
and then insert this;
insert into schedule values('2017-02-01','atlanta falcons',14,7);
Upvotes: 0
Reputation: 123
Please set default value of scoredifference column as 0 (or whatever you want), and try following query :
insert into schedule(gameday,oppoent,score,opponentscore) values('2017-02-01','atlanta falcons',14,7);
Thanks...
Upvotes: 0
Reputation: 3593
I don't think you should be trying to insert values into a computed column. Rather, this column will be computed on the fly when you actually query your table. Instead, try specifying the four column names whose data you are trying to insert:
INSERT INTO schedule (gameday, opponent, scoredifference, score)
VALUES
('2017-02-01', 'atlanta falcons', 14, 7);
But ... your values part contains 4 columns so match all fields.
Upvotes: 1
Reputation: 583
insert into tablename (column-list) values(value-list) , you need to specify the column-list if you are not inserting for all columns or not in order.
Upvotes: 0