The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

Error code caused by SQL query given in ‘Primary key constraints’ SQL lesson

Error code caused by SQL query given in ‘Primary key constraints’ SQL lesson

0
Votes
4
Answer

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,
customer_id INT,
item_code varchar(10)
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,
customer_id INT,
item_code varchar(10)
);
 
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. 

4 Answers

365 Team
0
Votes

Hi MeredithB!
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.
Best,
Martin
 

0
Votes

Hi Martin,
 
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.

365 Team
0
Votes

Hi MeredithB!
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!
Best,
Martin

0
Votes

Hi Martin,
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?
https://imgur.com/a/FrXmVqw
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.

×
Ready to Learn
Data Science?
50% OFF