How to get row row id in sql server

I have one table CSBCA1_5_FPCIC_2012_EES207201222743having two columns employee_idandemployee_name

I used the following query

SELECT ROW_NUMBER() OVER (ORDER BY EMPLOYEE_ID) AS ID, EMPLOYEE_ID,EMPLOYEE_NAME 
FROM CSBCA1_5_FPCIC_2012_EES207201222743 

But it returns the rows in ascending order employee_id, but I need the rows so that they are inserted into the table.

+5
source share
3 answers

SQL Server , , . employee_id IDENTITY, 100% , ( ID SET IDENTITY_INSERT ON). employee_id IDENTITY, , , , :

SELECT 
   ROW_NUMBER() OVER (ORDER BY EMPLOYEE_ID DESC) AS ID, 
   EMPLOYEE_ID,
   EMPLOYEE_NAME 
FROM dbo.CSBCA1_5_FPCIC_2012_EES207201222743
ORDER BY ID;

, , ( ).

ALTER TABLE dbo.CSBCA1_5_FPCIC_2012_EES207201222743 
-- wow, who named this?
  ADD CreatedDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP;

, , INSERT INTO dbo.whatever SELECT/VALUES() - . , .

+12

, %% physloc %%, .

. Oracle RowID SQL Server

+6

SQL does not. The order of tuples in the table is not sorted by input date. Many people include a column that stores the input date to get around this problem.

+2
source

All Articles