I add column to table as:
RedMarkItemsId (IDENTITY(1,1) NOT NULL PRIMARY KEY)
TaskId (UNIQUEIDENTIFIER)
CreationDate (DATETIME)
CreatedBy (UNIQUEIDENTIFIER)
I want to create column like:
ALTER TABLE RedMarkItems ADD Item1 BIT DEFAULT(0)
But when I try to insert some values:
INSERT INTO RedMarkItems
VALUES (
'9B093907-2072-4F59-A55C-0003CE89EF9E',
GETDATE(),
'6074CAEA-7A8E-4699-9451-16C2EAF394EF')
It throws error:
Column name or number of supplied values does not match table definition.
Why I'm getting this error if I set DEFAULT(0) to that new column?
Table create script:
CREATE TABLE RedMarkItems
(
RedMarkItemsId INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
TaskId UNIQUEIDENTIFIER,
CreationDate DATETIME,
CreatedBy UNIQUEIDENTIFIER
)
identitycould instead be anywhere positionally in the list of columns, so SQL Server can't guess that the 3 values you supplied are supposed to go into the 3 columns you named; you have to tell it. This is a good thing: the language is being consistent, rather than being overly charitable by making an assumption if theidentityhappens to be the 1st column, where that assumption could lead to unexpected results and would only work in 1 situation.