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
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
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` ;
Related
[![I am getting error code: 1050 (as you can see at from the output in the image) Table already exists, when it doesnt. Can anyone help me with this?
The question reads: Create a view called ‘computer_science_students’ for the SELECT query created under Index step ]1]1
Sounds like you have Schroedinger's table...
you probably have a broken table. Try:
Syntax
The syntax for the DROP VIEW statement in MySQL is:
DROP VIEW [IF EXISTS] view_name;
view_name - The name of the view that you wish to drop.
IF EXISTS - Optional. If you do not specify this clause and the VIEW does not exist, the DROP VIEW statement will return an error.
If you have sufficient permissions, delete the data files (in /mysql/data/db_name)
I want to look at a query used to create a table. The table was created already. I've seen this done in the past in the command console, but I cant find how to do this now. It was something like:
show create; --OR
select create; --none of these work
After running that it will display the query and some details about mysql.
SHOW CREATE TABLE tbl_name is the syntax in mysql. MySql Refernce.
maybe you're talking about show create table
I want to copy mysql table from one database to another using mysql command line
I am trying to executing commmand
DROP TABLE IF EXISTS `db1.tablename`; CREATE TABLE `db1.tablename` like `db2.tablename`;
but it is giving me error no database is selected.
but if I fire
use db2
DROP TABLE IF EXISTS `db1.tablename`; CREATE TABLE `db1.tablename` like `db2.tablename`;
then it is create table db1.tablename inside db 2.
How to fix it ?
I think your create statement should look like this:
CREATE TABLE `db1.tablename` SELECT * FROM `db2.tablename`;
The table name in your query includes the database name without separation. It should be something like:
DROP TABLE IF EXISTS `db1`.`tablename`;
CREATE TABLE `db1`.tablename` like `db2`.`tablename`;
I want to dump only view object from mysql databases in the following format :
CREATE OR REPLACE ALGORITHM=UNDEFINED DEFINER=`root`#`localhost` SQL SECURITY DEFINER VIEW
`v_sample` AS
SELECT
`a`.`id` AS `id`,
`a`.`code` AS `active`,
`a`.`title` AS `title`
FROM t_test a;
the script above is the best practive i have ever had... no problem with privilege issue like can not drop the temporary view table, etc
Notes :
I found inside the dump script database, that mysql treat the view object as table first then will be replaced by the real view.
You need to use SHOW CREATE VIEW statement.
SHOW CREATE VIEW v_sample
Is there an easy way to extract table DDL information, via a query, using either Ms or My SQL server? (preferably both?)
For example, using MySQL Administrator / Navicat for MySql, there is a "DDL" function, which generates the "create table foo (....)" script.
Is there any way to get this information from a query itself, such as:
Select DDL from foo where table_name='bar';
Any have the "Create table bar (.....)" returned to me?
If not - any suggestions?
it's mysql-specific, but SHOW CREATE TABLE <table-name> gives you the DDL for a table.
You have to create that yourself.
You can query INFORMATION_SCHEMA.COLUMNS for the column name and data type.
You can't get the CREATE Table text in a cross platform way, but you can get enough information to build it yourself from the INFORMATION_SCHEMA views.