Home > Software engineering >  How to automatically sort new record in database table according to the primary key?
How to automatically sort new record in database table according to the primary key?

Time:12-09

I have created a data table "user" in OceanBase, the primary key is id, there are 3 records as follows:

'1001','haha','[email protected]'
'1002','hehe','[email protected]'
'1004','oror','[email protected]'

Then, When I added a new record '1003', it is actually sorted after '1004', not after '1002'.

INSERT INTO user (id,name,email) VALUES ('1003','hihi','[email protected]')

How can I sort this record after '1002'?

CodePudding user response:

You do not need to sort the table itself. Just order your query like

SELECT *
FROM user
ORDER BY id ASC; 
  • Related