sql-insert

SQL Insert into table only if record doesn't exist [duplicate]

匆匆过客 提交于 2019-12-28 04:51:32
问题 This question already has answers here : Check if a row exists, otherwise insert (11 answers) MySQL Conditional Insert (12 answers) Closed 6 years ago . I want to run a set of queries to insert some data into an SQL table but only if the record satisfying certain criteria are met. The table has 4 fields: id (primary), fund_id , date and price I have 3 fields in the query: fund_id , date and price . So my query would go something like this: INSERT INTO funds (fund_id, date, price) VALUES (23,

Rails: attempting save an existiing row but rails generates sql insert instead of update

给你一囗甜甜゛ 提交于 2019-12-25 18:19:20
问题 The error When I have a new record, I don't have a problem. When I have an existing record I'm trying to update, an exception (see below) is thrown. The following two variants of Rails code both throw the same exception when I have an existing row in my email_addresses table I wish to update: ret = @email_address.update(email_address_id: @email_address.email_address_id) I have also tried ret = @email_address.save and get the same exception. The exception When I have an existing record I wish

how to update data from datagridview with sqldatabse in vb.net

你说的曾经没有我的故事 提交于 2019-12-25 06:59:38
问题 i use another form editting data. when i double click the selected row in datagridview it will transfer the data in another form(frmEdit). i use this codes but it seems not working, how can i fix this. please help. Dim queryEdit As String = String.Empty queryEdit = "update dataContactDB set con_Name=@Name, con_Phone=@Phone, Address=@Address, Company=@Company, Gender=@Gender.text where con_Phone=txtPhone.text" Using conn As New SqlConnection(dbFunction.db) Using comm As New SqlCommand With

inserting multiple mysql rows php Android

时光总嘲笑我的痴心妄想 提交于 2019-12-25 02:24:32
问题 Im trying to insert multiple mysql rows in an external database using a php script and Android. I pass a JSONObject to the PHP script from Android and Im trying to use this data to update multiple rows of a mysql database at once. The problem is in the PHP script PHP $con=mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $json = $_POST['json']; $array = json_decode($json, true); for ($i = 0; $i < 3; $i++) { $name =

Missing Expression for insert statement in PL/SQL ODBM?

喜夏-厌秋 提交于 2019-12-25 01:32:41
问题 I'm attempting to populate an object-relational database in PL/SQL on Oracle SQL Developer, and keep getting the error ORA-00936: Missing Expression. I've attempted different fixes, but they all result in different errors. The database was provided, and the INSERT statement is all mine. The result should be inserting into the table properly, but it isn't, and I'm at a loss on how to progress. -- create OMDB -- ----------------- -- drop tables -- drop table albums / drop type disk_type / drop

Insert multiple data from subquery into another table in postgres sql

半腔热情 提交于 2019-12-25 00:43:21
问题 I have table alpha with two columns id school_name I have another table beta which has around 600 rows of data with following columns id school_name school_state school_city now i want to select school_name from beta and insert it into alpha something like insert into alpha (school_name) values(select school_name from beta ) but for all data ,I know it can be done with procedures but pgsql doesn't support procedures unlike mysql ,so how to achieve it? 回答1: The INSERT INTO ... SELECT syntax

Postgres 9.6: Inserts very slow after reboot

梦想与她 提交于 2019-12-24 21:27:53
问题 I'm experiencing a strange issue when importing data into postgres. I have an import script that runs once daily at night via cronjob on a Linux OS ( Linux 4.9.0-5-amd64 #1 SMP Debian 4.9.65-3+deb9u2 (2018-01-04) x86_64 GNU/Linux ). The process reads a file containing about 2 million rows and inserts these into a table in batches (batch size 25.000). This takes roughly 2 to 2.5 minutes, which is absolutely reasonable. The table has 3 indexes and meanwhile contains more than 130M rows. To

ORMLite column with default

99封情书 提交于 2019-12-24 20:12:52
问题 I have a non null column defined with a default: @DatabaseField(dataType = DataType.TIME_STAMP, columnDefinition = "DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL") private Date createdDate; When trying to save a row with the createdDate field unset, I get the following error: [SQLITE_CONSTRAINT_NOTNULL] A NOT NULL constraint failed (NOT NULL constraint failed: ORMLite is probably trying to explicitly insert a NULL value into the field. Adding persisted = false to the annotation avoids this, but

How to insert dynamically added text boxes into MySQL database

别来无恙 提交于 2019-12-24 16:22:15
问题 I used Javascript to dynamically add textbox in order for the user to add more items in one process. Here's the code that add textboxes : <script type="text/javascript"> var quantity = document.getElementById('quantity'); var item = document.getElementById('item'); var serial = document.getElementById('serial'); var property = document.getElementById('property'); document.getElementById('add').onclick = function () { var input = document.createElement('input'), div = document.createElement(

Alternative to RETURNING with INSERT…SELECT

穿精又带淫゛_ 提交于 2019-12-24 16:05:57
问题 There's this scenario which involves inserting into a table by copying some columns from another table and returning the generated key out of this insert. Using Oracle Database. Which basically by instinct result to writing this query. INSERT INTO TBL_XXX SELECT COLA, COLB, COLC FROM TBL_YYY RETURNING COLA INTO COL_RES Which is not allowed for some valid reason. Is there an alternative to this? 回答1: You're using the insert into ... select from construct. So potentially your statement will