Hi i am trying to insert 10000 records in to a table, by using this command.
CREATE TABLE mytable(
id INTEGER PRIMARY KEY,
TEXT INTEGER NOT NULL,
OLDID iNTEGER NOT NULL,
Firstname VARCHAR(50) NOT NULL,
Middlename VARCHAR(50) NULL,
last_name VARCHAR(75) NOT NULL,
EMAIL VARCHAR(225) NOT NULL,
STATUS BOOL NOT NULL
);
DECLARE @i int
declare @rows_to_insert int
SET @i = 6
set @rows_to_insert = 10000
WHILE @i < @rows_to_insert
BEGIN
INSERT INTO mytable VALUES (@i, @i,@i,'john'+@i,null,'Test','john'+@i+'@someone.com','Active');
set @i = @i+1
END
But i am getting this Error.
Msg 8101, Level 16, State 1, Line 8
An explicit value for the identity column in table ‘mytable’ can only be specified when a column list is used and IDENTITY_INSERT is ON.
The table has an identity column. You need to explicitly state the rest of the columns in the insert statement. I might assume that your first column is the identity. Then it would look something like:
Of course, where is you would have your column names. It is always a good idea to list the column names, by the way.