MySQL View – Primary Key Problem

database-designMySQLprimary-keyview

I have 3 tables. and I want to create a view. There is no problem about generating SQL query and creating a view.

But when I want to use this view in my web app, it says me (LIKE THIS):

Your view's column doesn't have a primary key

So I want to set a PK to a column in my view.

Please help. Thanks.

Best Answer

You can't have a PRIMARY KEY on a VIEW. See here, here . You have to put PRIMARY KEYs and INDEXes on the underlying tables. A VIEW is a stored query - you can't have KEYs on a query.

Related Question