Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

primary key in mysql view

Status
Not open for further replies.

compudude86

IS-IT--Management
Jun 1, 2006
46
0
0
ok, so i have a view, how would i put a primary key into it? i have this code:

DROP VIEW IF EXISTS `Book`.`view`;
CREATE ALGORITHM=UNDEFINED DEFINER=`server`@`` SQL SECURITY DEFINER VIEW `view` AS select `Products`.`ID` AS `ID`,`Products`.`Description` AS `Description`,`Products`.`Size` AS `Size`,`Products`.`Pack` AS `Pack`,`Products`.`List` AS `List`,`Products`.`Net` AS `Net`,`Products`.`Discount` AS `Discount`,`Products`.`NetBtl` AS `NetBtl`,`Products`.`SRP` AS `SRP`,`Products`.`Vendor` AS `Vendor`,`Products`.`Date` AS `Date`,concat(round((((`Products`.`SRP` - `Products`.`NetBtl`) * 100) / `Products`.`SRP`),0),_utf8'%') AS `GPM` from `Products`;

how do i make `ID` show as a primary key?
 
A view does not have a "primary key"; that only applies to tables where a unique index may be required. If you are displaying the contents of a view, the base table's primary key could be regarded as the "primary key" of the view.
 
I recommend that you choose another name for your view:

CREATE ... VIEW `view`


Although backticks will allow you to use MySQL keywords as identifiers, it's not a good idea to do so.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top