2

If we have query for creating table like this..

create table if not exists food ( id int not null auto_increment, user_id int, name varchar(30), constraint pk_food primary key(id,name), foreign key(user_id) references userss(id) ); 

What does pk_food mean in this example? I know this is a constraint name, but for what we should be give a name for constraint, if its working without?

create table if not exists food ( id int not null auto_increment, user_id int, name varchar(30), primary key (id, name), foreign key (user_id) references userss(id) ); 

I mean.. how to use these names and for what we need it?

1

1 Answer 1

5

You gives constraints names for basically two reasons:

  • You can better understand the error message when the constraint is violated.
  • You can more easily find the constraint if you want to delete it.
Sign up to request clarification or add additional context in comments.

1 Comment

thank you! because i not found any information in doc

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.