Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 After Keyword is not working in sql

Author  Topic 

suvis10
Starting Member

1 Post

Posted - 2011-12-27 : 01:38:23
Hi


I am using sql 2005 .i want to create a new field using "after"
i used below query but it says

error:incorrect syntax near after

alter table sessions add speakercredential nvarchar(max) after SpeakerTitle

can u pls help me

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-12-27 : 01:48:27
You can't do that in SQL Server.

Order of column in a table is irrelevant. You can specify the column order that you need in the SELECT statement.






KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-27 : 02:24:57
quote:
Originally posted by suvis10

Hi


I am using sql 2005 .i want to create a new field using "after"
i used below query but it says

error:incorrect syntax near after

alter table sessions add speakercredential nvarchar(max) after SpeakerTitle

can u pls help me



the column position in a table is fixed and is available from ORDINAL_POSITION column of INFORMATION_SCHEMA.COLUMNS view.
Once created you cant change it.
And as Tan points out its irrelevant as you can always return the columns in the order you want by specifying it in select list



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-12-27 : 08:02:52
quote:
Originally posted by suvis10

Hi


I am using sql 2005 .i want to create a new field using "after"
i used below query but it says

error:incorrect syntax near after

alter table sessions add speakercredential nvarchar(max) after SpeakerTitle

can u pls help me



You can create a view that has columns with the preferred order. If you need it in a table, use SSMS design option to do this

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -