logo
down
shadow

Is it okay to update primary key field to shift a record to the top?


Is it okay to update primary key field to shift a record to the top?

Content Index :

Is it okay to update primary key field to shift a record to the top?
Tag : mysql , By : ranja
Date : November 23 2020, 01:01 AM

hope this fix your issue No this is not a good idea.
Primary keys are used for two reasons: looking up records and to allow for foreign key references.

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

how to update a record without worrying about primary key


Tag : ruby-on-rails , By : dormsbee
Date : March 29 2020, 07:55 AM
should help you out In ActiveRecord how can we update a record without worrying/knowing primary key.
a = Address.find_by_cid(15)
a.user_name = 'Samuel'
a.save

Update a record by Primary Key or by Unique Key


Tag : sql , By : Priya
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further This question bears 2 different aspects.
The goal: what you want to achieve is to update a given row. Any means allowing you to reach this point is good; in other terms, if the unique key, the primary key or any other combinaison of columns not listed under any unicity constraint would be ok then you might use it. The performances: as any other query you really want to go fast and straight to the point. What does it mean? It means that you have to chose the most efficient filter in you where clause. You can measure this by:

Update record's foreign key field based on a newly inserted record's primary key


Tag : sql , By : itsmegb
Date : March 29 2020, 07:55 AM
I wish this help you For each record in table A I want to update the foreign key value of one of the fields based on new inserted record's scope_identity in table B. , You can use a cursor to loop through TableA and create the records:
DECLARE @Id int
DECLARE @ForeignKey int

DECLARE C CURSOR FOR SELECT Id FROM TableA

OPEN C

FETCH NEXT FROM C INTO @Id

WHILE @@FETCH_STATUS = 0
BEGIN
    INSERT INTO TableB VALUES (value1)
    SET @ForeignKey = SCOPE_IDENTITY()

    UPDATE TableA
    SET ForeignKey = @ForeignKey
    WHERE Id = @Id

    FETCH NEXT FROM C INTO @Id
END

CLOSE C
DEALLOCATE C

Ruby on rails active record: update a field by another field in the same record using update_all


Tag : ruby-on-rails , By : ikey
Date : March 29 2020, 07:55 AM
I hope this helps you . How can I use update_all for the following purpose: , In Rails4, you can do
Model.where(id: 1).update_all("field = field2 * 2")
Model.update_all("field = field2 * 2", {:id => 1})

What is the REST way to update a record without primary key?


Tag : rest , By : Frank Rotolo
Date : March 29 2020, 07:55 AM
will be helpful for those in need I've created a REST API. According to my design, we have to store user's blood sugar level per daily basis. ,
Is there any way to achieve this (or similar) result with REST?
GET /users/1/blood-sugar/

200 OK

{
    "measureDate": "2019-05-03",
    "bloodSugarLevel": 90
}

PUT /users/1/blood-sugar/
{
    "measureDate": "2019-05-04",
    "bloodSugarLevel": 86
}

204 No Content

PUT /users/1/blood-sugar/
{
    "measureDate": "2019-05-04",
    "bloodSugarLevel": 105
}
Related Posts Related QUESTIONS :
  • change engine type from MyISAM to InnoDB
  • Need mysql query to find total sum as per matched query
  • json_table syntax and structure
  • Is there any way in sql query to rank certain value in ordered set of records such that ranking reset after it encounter
  • not able to login in google cloud storage sql instance
  • Inserting data into MySQL database with VBA
  • Make (user_id&music_id) unique in Likes table and Dislikes table
  • Can't do 50k insertion using bulkCreate
  • SQL syntax to get data IN date
  • How to get 4-byte emojis to store correctly in mysql 5.7?
  • How to create an in-memory database for PHPUnit testing?
  • How to write an SQL query to fetch the id in a column that has all the required data in some other column?
  • Invalid COLUMN in the select list because it is not contained in either an aggregate function or the GROUP BY clause
  • How to get actual index number of rows in MySQL when using Where clause
  • SQL Table Relationship
  • How to fix "FUNCTION doesnt exist" error in mysql?
  • Importing .bak from MSSQL into MySQL database
  • Aggregate query with distinct subquery kills every connection
  • How do i use and with multiple or condition?
  • How to fix 'The server requested authentication method unknown to the client [caching_sha2_password]' on docker compose?
  • In Mysql How to fetch distinct row value from a column1 and sum(column 2 row value) group by invoice number
  • MySQL ORDER BY field with a toggle
  • How to insert system's Date into Table
  • Aws lambda function too many connection issue rds
  • MYSQL - join 2 tables - sort in time
  • SQL code to select records where field_A matches the field_A value of a certain field_B value
  • How to model Amazon Redshift external table for changing column structure?
  • Query the list of CITY names from STATION that do not start with vowels and do not end with vowels. Your result cannot c
  • how to get rows with time for each minute for last 30 minutes
  • SQL Query With Between ,AND & OR in Where Clauses Not Given Correct Answers
  • ER_PARSE_ERROR: You have an error in your SQL syntax;
  • How to write normal sql queries inside controller in laravel
  • MySql query between range values(single record)
  • Set length conditions on text column in MySQL table
  • Mysql order of sorting
  • Sequelize raw queries TextRow and getting data out of it
  • Comparing the contents of two csv files, where the relation between the two files is specified in a third file?
  • Can 1 primary id link to multiple ids in one table?
  • Rewrite MySQL query and make it short
  • Why are parentheses used in JOIN USING clauses
  • Delete from row to row in phpadmin
  • Inserting Data into a table
  • How to efficiently get a entry with highest version in mysql table
  • How do I create views in dolphindb?
  • MySQL - update with inner join is creating nulls
  • Should i rather use a subquery or a combined WHERE?
  • INSERT INTO using data from other table causing ERROR 1064
  • How to display a MySQL table completely?
  • Can create procedure without using delimiter in MySQL?
  • distributed crawler and consistency
  • How to use mysql in node with Typescript
  • Is there any collation to differentiate 'е' and 'ё' in case insensitive way?
  • How to grant all privileges to specific user to remote ip
  • MySQL - Why is Safe Update Mode blocking this UPDATE command?
  • Can someone tell me why this query isn't working please?
  • At what time will MySQL execute events that are scheduled every DAY?
  • Same execution path, data and schematics; different query times
  • Liquibase commits changeset partially
  • sql query customer who ordered more than 15 times
  • How can I find the location visited by all employees in this sql table?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com