The SQL lesson Primary key constraints gives the following query code to use at 3:18 into the video:
create table sales
purchase_number int auto_increment,
date_of_purchase date primary key,
primary key (purchase_number)
I typed the above directly off the video screen. However, this code does not seem to work. I get the following error message:
17:16:04 create table sales ( purchase_number int auto_increment, date_of_purchase date, customer_id INT, item_code varchar(10) ) Error Code: 1075. Incorrect table definition; there can be only one auto column and it must be defined as a key 0.000 sec
I went back to the earlier exercise and used the following, which did work.
create table sales
purchase_number int not null primary key auto_increment,
date_of_purchase date not null,
Can someone please tell me what I’ve done wrong, that the query given at 3:18 in the Primary key constraints video gave me an error?
Thank you in advance.
Thanks for reaching out!
With the first query, you’ve defined two primary keys – date_of_purchase, and purchase_number. And you can’t have more than one primary key (and that’s what the error message suggests).
Your second query is correct – it contains only one primary key, purchase_number.
Please revise the code we’ve suggested – we can’t have shown two primary keys, I believe!
Hope this helps.
Thanks for your answer. I assure you, I copied the text exactly as per the video. Please open the video to check it.
I took a screenshot to show you – I have tried adding it here but I can’t. You’ll have to go to the video to check, I gave the exact name of the video and the time stamp in my original message.
Can you please upload your screenshot in https://imgur.com/? Thank you.
Otherwise, my previous reply was based on the code you had pasted above!
I have uploaded the image to Imgur as requested. The image from the tutorial video is on the left, and my screen is on the right. You can see it was throwing up an error on line 7 at the open brackets for some reason?
Also, I did indeed mistype in my code above – sorry about that. I should have just uploaded the image in teh first place, but I was really rushing!
Thanks in advance for letting me know where my query went wrong.