Combine the creation and insert into a single statement:
CREATE TABLE IF NOT EXISTS tableName ( id int(9) NOT NULL, col1 int(9) DEFAULT NULL, col2 int(3) unsigned zerofill DEFAULT NULL, PRIMARY KEY(id) ) ENGINE = InnoDB DEFAULT CHARSET = latin1 AS SELECT 1 AS id, 10 AS col1, 5 AS col2;
If it doesn’t create the table, AS SELECT ...
clause is ignored.
Related Posts:
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- Unknown column in ‘field list’ error on MySQL Update query
- Unknown column in ‘field list’ error on MySQL Update query
- MySQL – Operand should contain 1 column(s)
- MySQL “CREATE TABLE IF NOT EXISTS” -> Error 1050
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- How do I use properly CASE..WHEN in MySQL
- How can I do a FULL OUTER JOIN in MySQL?
- MySQL query String contains
- What’s the difference between VARCHAR and CHAR?
- Case statement in MySQL
- How to declare a variable in MySQL?
- MySQL Cannot Add Foreign Key Constraint
- How to split the name string in mysql?
- How do I import an SQL file using the command line in MySQL?
- Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
- mysql Foreign key constraint is incorrectly formed error
- MySQL: Invalid use of group function
- How can I return pivot table output in MySQL?
- Compare dates in MySQL
- MySQL “WITH” clause
- MySQL Multiple Joins in one query?
- Error Code: 2013. Lost connection to MySQL server during query
- MySQL syntax for Join Update
- Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
- how to drop partition without dropping data in MySQL?
- MySQL combine two columns into one column
- Simple way to calculate median with MySQL
- Error 1046 No database Selected, how to resolve?
- MySQL Error 1264: out of range value for column
- Remove duplicate rows in MySQL
- How to SUM and SUBTRACT using SQL?
- Cast from VARCHAR to INT – MySQL
- SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax — PHP — PDO [duplicate]
- How do you force mysql LIKE to be case sensitive?
- MySQL – UPDATE multiple rows with different values in one query
- How to create a MySQL hierarchical recursive query?
- ERROR 1148: The used command is not allowed with this MySQL version
- Insert into a MySQL table or update if exists
- How to round down to nearest integer in MySQL?
- MySQL starts with searching issue
- Query to convert from datetime to date mysql
- Is it possible to GROUP BY multiple columns using MySQL?
- MySQL error: key specification without a key length
- Best way to test if a row exists in a MySQL table
- Check if MySQL table exists without using “select from” syntax?
- MySQL equivalent of DECODE function in Oracle
- mysql update column with value from another table
- The used SELECT statements have a different number of columns
- PostgreSQL create table if not exists
- How to delete from multiple tables in MySQL?
- MySQL: Can’t create table (errno: 150)
- How to copy a row and insert in same table with a autoincrement field in MySQL?
- Join vs. sub-query
- Alternative to except in MySQL
- Equivalent of explode() to work with strings in MySQL
- ROW_NUMBER() in MySQ
- MySQL OPTIMIZE all tables?
- MySQL INSERT INTO table VALUES.. vs INSERT INTO table SET
- MySQL – Get row number on select
- MySQL error: Unknown column in ‘where clause’
- How to truncate the text returned for a column in a MySQL query
- Using union and order by clause in mysql
- MySQL LIKE IN()?
- Case in Select Statement
- Self Join to get employee manager name
- Mysql: Setup the format of DATETIME to ‘DD-MM-YYYY HH:MM:SS’ when creating a table
- Why does NULL = NULL evaluate to false in SQL server
- ORA-00918: column ambiguously defined in SELECT *
- How to parse XML data in SQL server table
- ERROR 1452: Cannot add or update a child row: a foreign key constraint fails
- Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 4 (Year)
- SQL selecting rows by most recent date with two unique columns
- Oracle: If Table Exists
- How to calculate age (in years) based on Date of Birth and getDate()
- How to create id with AUTO_INCREMENT on Oracle?
- Text was truncated or one or more characters had no match in the target code page including the primary key in an unpivot
- How can I group by date time column without taking time into consideration
- Update query using Subquery in Sql Server
- “This SqlTransaction has completed; it is no longer usable.”… configuration error?
- How to execute mulitple statement SQL queries using $wpdb->query?
- Return number of items in a table with post id
- How do I find which articles are missing a featured image in The WordPress database?
- Debugging WordPress
- Importing Geo data into wordpress database
- Pull data and display as rows and columns
- Speeding SQL queries for a large database?
- I need a SQL command to delete specific authors and all posts connected with them
- How to get INSERT errors from $wpdb?
- How can i restore only Blogs from a SQL backup file?
- Sql query does not work well
- How to change post published date to today date with SQL
- Do I need to sanitize $_POST[‘keyword’] before send to ‘s’ parameter?
- Display a number value from mysql query in WP
- how to SELECT meta values that are not null?
- Conditional statement within WP SQL query
- Sql query returns empty. But not
- SQL – JOIN last child
- Delete posts with word count less than x number of words
- Possible SQL injection. How to locate and fix?