I have a table containing an identity column as well as a column representing the creation date:
CREATE TABLE dbo.OrderStatus
(
OrderStatusId int IDENTITY(1, 1) NOT NULL,
CreationDate datetime NOT NULL default GETDATE(),
CONSTRAINT PK_OrderStatus PRIMARY KEY(OrderStatusId)
)
Since the identity column generates a value by itself and the CreationDate is always going to be the current date (GETDATE()
), I can add a row thanks to DEFAULT VALUES
:
INSERT INTO dbo.OrderStatus DEFAULT VALUES;
But what can I do if I want to add, let's say, three records?
Current solution (edited some input since it didn't make any sense)
For now, in order to do what I want, I add several rows with VALUES
:
INSERT INTO dbo.OrderStatus (CreationDate)
VALUES (GETDATE()),
(GETDATE()),
(GETDATE())
Although, I'd prefer to know the equivalent of INSERT INTO .. DEFAULT VALUES
for multiple rows, in case that I add another column with a default value later on.
Is there a way to insert N rows into a table with DEFAULT VALUES
or in a similar way?
INSERT INTO DEFAULT VALUES
equivalent for multiple rows. – Pyrography