简体   繁体   中英

How to rearrange columns in a table in C#

I have created a table "simple gate pass table".

I added some columns: ID, Serial, Date, To, Description, Authorized By.

afterwards, I created this table and later I realized I needed to add 1 more column "From"

but now it won't let me Re-edit existing columns and neither it lets me arrange columns.

在此处输入图片说明

This is MSSQL-related question and it has nothing to do with C#.


IIRC MSSQL does not allow you to neither rearrange column order nor add column after/before any other. You can only drop column or add one (at the end of the table). If you want to select/display data in some specific order use a SELECT clause with appropriate order, eg:

SELECT id, serial, date, from, to, description, authorized_by ...

By the way, from or date are not the very best choices for column names as they are reserved words in most SQL dialects.

you can change order of columns in management studio as follows:

  1. Right click on table name in object explorer and select Design. List of columns will open.
  2. In the newly opened list of columns, left click and drag column name to the position you want.
  3. Press ctrl+s to save.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM