Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8877893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:34:48+00:00 2026-06-14T19:34:48+00:00

=============== | id | name | =============== | 1 | Ali | | 2

  • 0
===============
| id   | name |
===============
|    1 | Ali  |
|    2 | ahmd |
|    3 | jada |
|    4 | nisr |
|    5 | sara |
|    6 | mona |
|    7 | dana |
===============

I want to re-order ID when I delete any row like id=5 and be like that =>

===============
| id   | name |
===============
|    1 | Ali  |
|    2 | ahmd |
|    3 | jada |
|    4 | nisr |
|    5 | mona |
|    6 | dana |
===============

also the same this if I insert a row with id=2 name=yafa, how to re-order the table without duplicate any value and to be like that

    | id   | name |
    ===============
    |    1 | Ali  |
    |    2 | yafa |
    |    3 | ahmd |
    |    4 | jada |
    |    5 | nisr |
    |    6 | sara |
    |    7 | mona |
    |    8 | dana |
    ===============
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:34:49+00:00Added an answer on June 14, 2026 at 7:34 pm

    This is assuming you always know what ‘id’ you are adding or deleting. (Also, you always work with only one row at a time).

    For a delete:

    DELETE FROM tableName WHERE id = 5;
    
    UPDATE tableName 
    SET    id = id-1
    WHERE  id > 5;
    

    For an insert:

    UPDATE tableName 
    SET    id = id + 1
    WHERE  id >= 2;
    
    INSERT INTO tableName (id, name) VALUES (2, 'yafa');
    

    Btw, why would you want to do this. Set the column ‘id’ to be an auto-increment field and let the database deal with it. Do you care if you are skipping numbers ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Name: <%= Html.TextBox(txtName, 20, new { @class = hello }) %> I want that
I got an XML which looks like: <Student> <SSN>630-44-3532</SSN> <Name> <firstName>Ali</firstName> <lastName>Daria</lastName> </Name> ...
The name says it all really. I suspect that insertion sort is best, since
Which name need the sql-file in the sql folder? When I want to load
I have a two-dimensional array and want to sort it by name. I would
i have a Json result that i got through a webservice, now i want
These are my rows that I initially retrieved: 112 Cem Ceminay 210 Ali Salih
If I have multiple records in a SQL table like: name score ................................... sami
what I'm trying to do: from these tables --------------------------------- name date state --------------------------------- ali
i have a table like this : CREATE TABLE [Mytable]( [Name] [varchar](10), [number] [nvarchar](100)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.