insert-update

Unable to Hide Update Button in GridView Editing

Hi, I am using commandfield edit button to edit the row of the gridview. But unable to perform the basics. This gridview is in update panel. When I press Edit button it shows UPDATE and CANCEL button but when I press UPDATE button it updates the DB but UPDATE button doesn't go back to EDIT one. While Cancel is working as it should. L...

Is it possible to use the Sql MERGE syntax to UPDATE / INSERT data from another variable TABLE?

Hi folks, I wish to Insert or Update a row in a table - so I wish to try and use the MERGE syntax. My problem is that my data (to insert/update) exists in a variable table. I'm not sure how to write the correct syntax for the insert/update part. Here's my pseduo code :- -- Here's the Variable Table ... and not it has not PK. DECLARE @...

How does this SQL query to update a row if exists, or insert if not, work?

I'm working with some code. There are several queries whose effect is, if the row exists with some of the data filled in, then that row is updated with the rest of the data, and if the row does not exist, a new one is created. They look like this: INSERT INTO table_name (col1, col2, col3) SELECT %s AS COL1, %s AS COL2, %s AS COL3 FROM ...

Update the value of a field in database by 1 using codeigniter

Hello all I want to implement a SQL statement using codeigniter active record. UPDATE tags SET usage = usage+1 WHERE tag="java"; How can I implement this using Codeigniter active records? Regards ...

MySQL INSERT INTO Statement

I need some help with an insert statement. I've got: my_table_a: School Latitude Longitude Old School 38.6... -90.990... New School 38.6... -90.990... Other School 38.6... -90.990... Main School 38.6... -90.990... my_table_b: School Latitude Longitude City School Old School Centra...

Insert or Update without a loop?

I have table with two columns: ItemMaster (Item INT, Quantity INT) If an item is already there, then I should update the Quantity. Otherwise, I have to insert a Record in this table. Is this possible without Loop? I'm using SQL Server 2005. ...

How to get the original value of changed fields?

I'm using sqlalchemy as my orm, and use declarative as Base. Base = declarative_base() class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String) My question is, how do I know a user has been modified, and how to get the original values without query database again? user = Sess...

Converting INSERT commands to UPDATE

Hey there, I have two INSERT commands, that are useless to me like that because the two sets of rows - the ones that are already in the table, and the ones I have as INSERT commands - are not disjunct. Both commands insert lots of rows, and lots of values. Therefore I get the duplicate entry error if I want to execute those lines. Is ...

In MySQL, how do I insert only when row doesn't exist and update only when existing version is less

I am looking for a way to only insert when the row does not exist in MySQL, and update when the row exists AND the version of the existing row is less than (or equal to) the version of the new row. For example, the table is defined as: CREATE TABLE documents ( id VARCHAR(64) NOT NULL, version BIGINT UNSIGNED NOT NULL, data BLOB,...

best practice for maintaining ranking tables?

Using MySQL and PHP, I have a simple ranking table with 2 columns user and score. Once a week, I re-run the ranking script and it computes scores for each user. many users have new scores some do not some times there are new users to add to the table What's the best way to approach this with MySQL? Does update work if I need to add ...

Why are 2 rows affected in my `INSERT ... ON DUPLICATE KEY UPDATE`?

I'm doing an INSERT ... ON DUPLICATE KEY UPDATE for a PRIMARY KEY in the following table: mysql> describe users_interests; +------------+---------------------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+---------------------------------+------+...

How to pull out the name of the primary key column(s) of a MS SQL Server table?

I have a MS SQL Server Database with about 75 tables on it, and I am trying to insert records into tables if a record with the same primary key doesn't exist, or update if they do. I could hard code the primary keys for every table into my vb.net code, but I'd rather not as more tables are to be added at a later date and my code needs to...

UPDATE record if present; else INSERT

I want to update a record which may or may not be present in a table. If it is not present in the database then it will be inserted. To prevent from select I am using UPDATE statement first and checking affected_rows > 0 if not then I am inserting this record into the table. I was wondering if there is a better way to do this? ...

ON DUPLICATE KEY UPDATE with a multi field index

I have this test table with one row entry and 2 indexes, the first a primary key and then a unique index for a and b columns: CREATE TABLE IF NOT EXISTS `test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `a` int(11) NOT NULL, `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `a` (`a`,`b`) ) ENGINE=InnoDB...