user2638180
user2638180

Reputation: 1023

Why doesn't the autoincrement field work properly?

Well, first of all I'm using this online editor (that editor needs a browser like Chrome,Safari or Opera): http://www.w3schools.com/sql/trysql.asp?filename=trysql_delete, so maybe it's just a bug of the editor , but I'd find it strange, as it really looks like it's using a real database.

Anyway, I create a table this way in the editor:

CREATE TABLE Persons
(
ID int IDENTITY(1,1) PRIMARY KEY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)

Then I try to insert it with something like:

INSERT INTO Persons (FirstName,LastName)
VALUES ('Lars','Monsen')

And it does insert the values in LastName and FirstName but on ID it inserts a NULL, so it even makes the ID field to malfunction as a PRIMARY KEY.

I've checked that problem is with identity as a if I delete the IDENTITY(1,1) then ID field works a primary key field should.

Is there something I'm missing or is it just a bug?

Thanks for your attention.

Upvotes: 0

Views: 68

Answers (1)

librata
librata

Reputation: 150

Yep, it's definitely a bug. I've tested it.

Upvotes: 2

Related Questions