8

How do I update an entire table column

 2 years ago
source link: https://www.codesd.com/item/how-do-i-update-an-entire-table-column.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How do I update an entire table column

advertisements

I have a Micropost table with columns user_id and sender_id (both integers). I've just added the sender_id column and by default it's value is nil for existing table rows. As a one time thing I want all of the user_id values to be copied and pasted into the sender_id column for the rows already existing. some sort of migration required?


You can do this from rails console.

Micropost.update_all("sender_id = user_id")

Related Articles

How do I update my MySQL table column with a unique random sequence number?

I try to update my MySQL table column, and set random sequence number, begin from 1,2,3,etc. For example, I have total 38 row, so i need update it with number 1-38 (can't duplicate). i tried using: UPDATE TABLE SET VALUE=FLOOR(RAND()*38)+1 but it giv

SQL update statement - Attempt to update the entire table error

I'm using a Derby db and I'm trying to update every single column in one of my tables. I'm using the following statement: String stmt = "UPDATE APP.DATAVAULT SET DID = ?, DTITLE = ?, DUNAME = ?, DPASS = ?, DSANSWER = ?, DPIN = ?, DURL = ?, DNOTES = ?

Why does this SQL update the entire table?

I've been hit by the classic beginner mistake. As if I'd done an UPDATE with no WHERE clause. Here's the SQL: "UPDATE teams SET description = ? " + "FROM teams t " + "JOIN team_memberships tm ON t.id = tm.team_id " + "JO

How to ensure that it is possible to update a database table column only in one way?

I am using Ruby on Rails v3.2.2 and I would like to "protect" a class/instance attribute so that a database table column value can be updated only one way. That is, for example, given I have two database tables: table1 - full_name_column table2

How to hide or display the table column created using javascript data?

Do you know how to hide or show column when datatable's source is javascript? Methods for showing or hiding columns table = $('#example').DataTable(); var col = table.column("0").visible(false); work when data source is directly into html <ta

How can you update to a table in another database using postgres dblink?

The query that has to be executed is as simple as below - Update employee set is_done=true; The table that I want to update is only present in another database. I have been using these kinds of dblink queries. INSERT Into mytable select * from dblink

How to iterate through an HTML table column and enter values ​​in a Javascript matrix using JQuery

Let's say I have a table column with 10 rows, each with <td id="num"> and a text value. How can I use JQuery to loop through each row in the column and input the spins into a Javascript array? I thought the following code would do it, but

HTML: how to increase the width of table columns when the table is inside a div with a fixed width

The following piece of HTML code creates a table inside a div of fixed width. It seems that the "th,td" width is inherited from the parent div (but the W3 documentation says that it is not a inherited property!). How do I increase the width of t

How is a CSS display & ldquo; Table-column & rdquo; Held to work?

Given the following HTML and CSS, I see absolutely nothing in my browser (Chrome and IE latest at time of writing). Everything collapses down to 0x0 px. Why? <!DOCTYPE html> <html> <head> <style type="text/css"> section {

Update the third table column according to other 2 tables

I have 3 tables with below structure: ______________ | ContractInfo | |--------------| | ContractId | | QuotationId | | SupplierId | |______________| ____________ | Quotation | |------------| | Id | | ContractId | |____________| _____________________

How to Manually Update the Data Table with New JSON Data

I am using plugin jQuery datatables and load my data which I have loaded in DOM at the bottom of page and initiates plugin in this way: var myData = [ { "id": 1, "first_name": "John", "last_name": "Doe" }

How to save or retrieve a table column using Hibernate

I use Postgres and I have one column ufsinss character(2)[] like array. I created userType model to use, because I found some posts in google indicating the way to deal with this problem, because Hibernate doesn´t have native ways to deal with it. My

How do I update a model (table) of a different controller (or model)

I have a generic import table that allows the loading of csv files into different columns in my import table. The same import table is used for multiple types of imports, so I don't process the individual fields until the user is ready and tells me w

How to get values ​​from a table column, concatenate them with a string and insert them into another table?

How to: Get values from table1.column1 (e.g. abc) table1.column1=abc Concatenate them with certain fixed strings, e.g. xxx yyy zzz Insert the results as separate rows in table2.column2. The final result should be rows with values like this: table2.co

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK