So I am getting error from a CREATE TABLE even though that command is a dump from phpMyAdmin. I exported the the database and is trying to modify the structure through a text editor instead. I have not modified this command in anyway ( I have modified other parts). If I remove this CREATE TABLE then importing the .sql file goes through without a problem.
Just remove --6 in front of CREATE TABLE statement
--6 CREATE TABLE IF NOT EXISTS `owner` ( ...
^^^^
Should be just
CREATE TABLE IF NOT EXISTS `owner` ( ...
Here is SQLFiddle demo
Related
In MySQL user manual, it says the following command is way faster than the RENAME command since no table copy is required.
ALTER TABLE table1 RENAME TO table2;
http://dev.mysql.com/doc/refman/5.7/en/alter-table.html
However, is there anyway that we can quickly rename/overwrite a table into an existing table in MYSQL 5.6? I have tried the following command and it shows error "You have an error in your SQL synthax;"
ALTER TABLE table1 RENAME OVERWRITE TO table2;
Could any guru enlighten? Thanks.
Not quite sure where you saw that. But ...
RENAME TABLE old_table TO new_table;
This statement is equivalent to
the following ALTER TABLE statement:
ALTER TABLE old_table RENAME new_table;
Source: http://dev.mysql.com/doc/refman/5.7/en/rename-table.html
If you want to rename a table and a table with that name already exists, you need to first do.
DROP TABLE old_table
Because
MySQL checks the destination table name before checking whether the
source table exists. For example, if new_table already exists and
old_table does not, the following statement fails as shown here:
(gives an example)
I always get the error:
CREATE DATABASE bundesliga ERRORCODE 1007 CANT CREATE DATABASE bundesliga, database exists
Here is my code:
CREATE DATABASE bundesliga;
DROP TABLE IF EXISTS Liga;
CREATE TABLE Liga (
);
DROP TABLE IF EXISTS Spiel;
CREATE TABLE Spiel ();
Your Database Bundesliga already exists.
you have to drop your database first and then recreate it.
DROP DATABASE bundesliga;
CREATE DATABASE bundesliga;
DROP TABLE IF EXISTS Liga;
CREATE TABLE Liga (
);
DROP TABLE IF EXISTS Spiel;
CREATE TABLE Spiel ();
or use this
CREATE DATABASE IF NOT EXISTS bundesliga;
and to check if database exist.
SHOW DATABASES LIKE 'bundesliga';
You can use an IF NOT EXISTS clause to prevent the error:
CREATE DATABASE IF NOT EXISTS bundesliga;
If the database already exists, this does nothing. If it doesn't exist, it will be created.
Your database already exists. See error code 1007 here.
Your Database Bundesliga already exists. If you want to recrate you have to drop this before.
I have just come across the MySQL Commands out of sync; you can't run this command now error. It's come up on SO before, but those questions and answers refer to application-level code.
Here is a file I'm trying to import through phpmyadmin. (It is simplified from the real code.) I am confused because I have other groups of drop/create/call statements in other files which imported fine.
What is causing the error?
DROP PROCEDURE IF EXISTS `c9gtd`.`select_changes`;
CREATE PROCEDURE `c9gtd`.`select_changes`
(
IN `user_id` INT,
IN `days` INT
)
SELECT
0 AS `id`
;
CALL `c9gtd`.`select_changes`(-1,-1); -- Test
DROP PROCEDURE IF EXISTS `c9gtd`.`select_info`;
CREATE PROCEDURE `c9gtd`.`select_info` (IN `id` INT) -- ERROR IS HERE
SELECT
0 AS `id`
;
CALL `c9gtd`.`select_info`(-1); -- Test
This is because both stored procedures are SELECTs. All the stored procedures up to this point have been UPDATEs: having multiple CALLs in one connection is ok when no data is returned.
I run this query
CREATE TEMPORARY TABLE usercount SELECT * FROM users
I get this message
Your SQL query has been executed successfully ( Query took 0.1471 sec )
But when I try to access the newly created table using
SELECT * FROM usercount
I get this error
#1146 - Table 'abc_site.usercount' doesn't exist
Not sure why, I need to mention that I've did a good share of googling beforehand.
My version of PHPMyAdmin is 3.5.2.2 and MySQL 5.5.27
PHPMyAdmin (or rather PHP) closes the database connection after each screen. Thus your temporary tables disappear.
You can put multiple SQL statements in the SQL query box in PHPMyAdmin; this should be executed as one block and thus the temporary table is not deleted.
Temporary tables are temparar and after use thay Delete.
for example ,when insert data into database , first we can insert into temp table and thus when complete transaction , then insert into main table.
EXAMPLE :
//------------------------------------------
CREATE TEMPORARY TABLE TEMP
(
USERNAME VARCHAR(50) NOT NULL,
PASSWORD VARCHAR(50) NOT NULL,
EMAIL varchar(100),
TYPE_USER INT
);
INSERT INTO TEMP VALUES('A','A','A','1');
SELECT * FROM TEMP
//-----------------------------------------
Show A,A,A,1
in mysql i can create a table named "select" using the following statement
CREATE TABLE `SELECT` (
Id INT,
Name VARCHAR(255)
}
and it executed successfully and the table is created by the name "select" as you can see the image above. But the same couldn't be done in oracle 11g.
What would be the sql query that's required to create a table named "select" in other sql databases
I think you should use
CREATE TABLE "SELECT" ...
use dumme
create table [select]
(
i int
)
select * from [select]
i dont know why you in such need to create table with reserve word but in MS SQL server 2005 you can use the above statment to create a table with name select
Select is a reserved word, and tgus should actually not be used. The validation in mysql is just a little less strict.
Try using another name, like selectTable or selectId