5

I'm having a hard time trying to create a view in phpMyAdmin. I have a database named myDB and a table named myTable.

In phpMyAdmin I click on the SQL tab, type in :

SHOW CREATE VIEW myView;

I got this error MySQL said:

#1146 - Table 'myTable.myView' doesn't exist

I don't understand this error message at all, of course it doesn't exist, otherwise why would I want to create it in the first place? And why wouldn't mySQL allow me to create it? How do I create a view?

Thanks

Ben Dauphinee
  • 4,061
  • 8
  • 40
  • 59
Rich
  • 121
  • 1
  • 2
  • 7

2 Answers2

16
SHOW CREATE VIEW

The syntax you are using is not for creating view in SQL. it is to show the views you have created in SQL

You need to use the following syntax to create a view

CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
Vrunda Savaliya
  • 180
  • 1
  • 5
0

ALTER ALGORITHM = UNDEFINED DEFINER=**[YOUR_USERNAME]**@localhost VIEW **[YOUR_VIEW_NAME]** AS [YOUR_VIEW_QUERY];

Change the bold text above, example:

ALTER ALGORITHM = UNDEFINED DEFINER=`dadu_keeve`@`localhost` VIEW `view_banner` AS select `mst_banner`.`banner_uid` AS `banner_uid`,`mst_banner`.`banner_img` AS `banner_img`,`mst_banner`.`banner_alt` AS `banner_alt`,`mst_banner`.`banner_caption` AS `banner_caption`,`mst_banner`.`banner_link` AS `banner_link`,`mst_banner`.`banner_sort` AS `banner_sort`,`mst_banner`.`banner_tipe` AS `banner_tipe`,if((`mst_banner`.`banner_tipe` = 0),'BOX','FULL WIDTH') AS `banner_tipe_desc` from `mst_banner` ;
Imran Nababan
  • 99
  • 1
  • 6