sql-insert

What is reason for following sql code couldn't insert data?

人盡茶涼 提交于 2019-12-23 04:03:51
问题 My database have two column. One column is auto increment id(Primary Key) and other is 'Sentence' column. Manually type something and I can insert that value. But when I'm trying insert variable value that gives error message. I tried different ways. ('?') /( ? )/(?) Not work anything for me. int s1=9; String s2="Kasuni"; String sql = "INSERT INTO sentences (Sentence) VALUES ( ? )"; PreparedStatement pstmtJ = conn.prepareStatement(sql); //pstmtJ.setInt(1, s1); pstmtJ.setString(1,s2); pstmtJ

SQL Insert Row and copy inserted Auto-Increment id to another column

久未见 提交于 2019-12-23 03:07:31
问题 I am using PHP and MySQL. Goal: Insert a new row into a table with an auto-increment id column. While inserting this new row, I would like to copy the new inserted row's auto-increment id # into another column in the same row/entry. Upon creation, the new entry/row should have the auto-incremented id column and another column with the same number. My biggest concern: I need all of this to happen correctly and reliably, even while other transactions from other connections could be taking place

MySql Insert if not exist two column pair otherwise update

扶醉桌前 提交于 2019-12-22 10:46:39
问题 I got Mysql table like this CREATE TABLE IF NOT EXISTS tbl_member_doc_read ( `read_id` INTEGER(10) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT , `member_id` INTEGER(10) UNSIGNED NOT NULL , `doc_id` INTEGER(10) UNSIGNED NOT NULL , `status` INTEGER(1) DEFAULT '0', FOREIGN KEY (`member_id`) REFERENCES tbl_member(`member_id`), FOREIGN KEY (`doc_id`) REFERENCES tbl_doc(`doc_id`) ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci; lets say example data id that table read_id member_id doc

MySQL - insert if doesn't exist yet

孤人 提交于 2019-12-22 04:37:17
问题 I want to execute this MySQL query: INSERT INTO `cron-stats` (`user`) VALUES (".(int)$d['by-user'].") Whenever such user doesn't exist yet, as in: SELECT 1 FROM `cron-stats` WHERE `user` = ".(int)$d['by-user']." How can I execute this in one query? 回答1: you can use ON DUPLICATE KEY UPDATE INSERT INTO `cron-stats` (`user`) VALUES ('yourValue') ON DUPLICATE KEY UPDATE user = user; ON DUPLICATE KEY UPDATE but in order to perform the INSERT statement well, you need to set a UNIQUE index on column

MySQL - insert if doesn't exist yet

佐手、 提交于 2019-12-22 04:37:06
问题 I want to execute this MySQL query: INSERT INTO `cron-stats` (`user`) VALUES (".(int)$d['by-user'].") Whenever such user doesn't exist yet, as in: SELECT 1 FROM `cron-stats` WHERE `user` = ".(int)$d['by-user']." How can I execute this in one query? 回答1: you can use ON DUPLICATE KEY UPDATE INSERT INTO `cron-stats` (`user`) VALUES ('yourValue') ON DUPLICATE KEY UPDATE user = user; ON DUPLICATE KEY UPDATE but in order to perform the INSERT statement well, you need to set a UNIQUE index on column

Insert data from db to another db

こ雲淡風輕ζ 提交于 2019-12-21 10:57:09
问题 I want to take values from my old database tables to new database tables. Old db structure: Table I: Country CountryId CountryName New db structure Table II: Countries Id Name I used the following insert query like, select 'insert into Countries (Id, Name) select ', countryid, countryname from Country But I have the result like, insert into Countries(Id,Name) select 1 India insert into Countries(Id,Name) select 2 Any Country like that. but I need the result like, insert into Countries (Id,

Efficiently duplicate some rows in PostgreSQL table

我怕爱的太早我们不能终老 提交于 2019-12-20 23:31:14
问题 I have PostgreSQL 9 database that uses auto-incrementing integers as primary keys. I want to duplicate some of the rows in a table (based on some filter criteria), while changing one or two values, i.e. copy all column values, except for the ID (which is auto-generated) and possibly another column. However, I also want to get the mapping from old to new IDs. Is there a better way to do it then just querying for the rows to copy first and then inserting new rows one at a time? Essentially I

Insert values statement can contain only constant literal values or variable references in SQL Data Warehouse

[亡魂溺海] 提交于 2019-12-20 06:38:40
问题 Consider this table: CREATE TABLE t (i int, j int, ...); I want to insert data into a table from a set of SELECT statements. The simplified version of my query is: INSERT INTO t VALUES ((SELECT 1), (SELECT 2), ...); The real query can be much more complex, and the individual subqueries independent. Unfortunately, this standard SQL statement (which works on SQL Server) doesn't work on SQL Data Warehouse. The following error is raised: Failed to execute query. Error: Insert values statement can

Insert into wordpress database - Call to a member function insert()

 ̄綄美尐妖づ 提交于 2019-12-20 06:00:18
问题 Im having an issue with inserting data into the wordpress database through my plugin. My plugin uses a shortcode to display a form from which some calculations are made and then that information is the then supposed to be inserted into the database but I end up getting this message. I can't seem to get it to work?.. Any help would be appreciated greatly. PLUGIN CODE used for the insert: include_once($_SERVER['DOCUMENT_ROOT'].'/wp-config.php' ); $wpdb->insert( 'wp_wine_bookings', array( 'name'

how to write an insert query in Doctrine

半城伤御伤魂 提交于 2019-12-20 04:29:10
问题 How do I create an insert query in Doctrine that will perform the same function as the following SQL query: INSERT INTO target (tgt_col1, tgt_col2) SELECT 'flag' as marker, src_col2 FROM source WHERE src_col1='mycriteria' 回答1: Doctrine documentation says: If you want to execute DELETE, UPDATE or INSERT statements the Native SQL API cannot be used and will probably throw errors. Use EntityManager#getConnection() to access the native database connection and call the executeUpdate() method for