So I tried to make these following two tables with phpmyadmin.
create table category (
catId int identity(1,1),
catName varchar(20),
Constraint pk_category
PRIMARY KEY(catId))
create table subcategory (
subCatId INT IDENTITY(1,1),
catId INT,
subCatName VARCHAR(20),
CONSTRAINT pk_subcategory
PRIMARY KEY(catId,subCatId),
CONSTRAINT fk_subcat_cat
FOREIGN KEY(catID)
REFERENCES category(catId))
When creating the subcategory it shows this query error:
1075 – Incorrect table definition; there can be only one auto column and it must be defined as a key .
There aren’t two auto incremented columns in subcategory table, only the ‘subCatId’ is. What should be done?
4
Answers
You appear to be using SQL Server syntax, but run against MySQL. Use the correct syntax and it should work:
IDENTITY
in SQL Server roughly corresponds toAUTO_INCREMENT
in MySQL.This ref link may hep you more about this.
This is what MySQL states
So according to your requirement you’ve following choices.
subCatId
asPrimary Key
Unique
You have
Instead, just say