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
 column names

Author  Topic 

MirandaJ
Starting Member

35 Posts

Posted - 2005-12-27 : 15:26:08
At my work, we are upgrading a number of MS Access 2000 databases to SQL Server 2000. Many of the columns have names that do not follow the rules for Identifiers. For example there are columns with a numeric names 1,2,3,4,5,6,7,8,9. There are also columns with a hyphen in the name and columns that begin with a number and not an underscore or an alpha character. Plus there are columns with names like first, last, position, etc. (There was also columns with reserved words used as the names. I have changed those column names in the databases that I have already converted) Will leaving these names alone create a problem? The database serves as the backend to ASP pages.

Miranda

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-28 : 00:35:31
If the column names are numbers like 1,2,3,etc then you should access them by [1],[2],[]3],etc. It is better to change them. Instead of space and hypen use Underscore(_). Als refer this
http://vyaskn.tripod.com/object_naming.htm

Madhivanan

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

Kristen
Test

22859 Posts

Posted - 2005-12-28 : 06:11:13
Alternatively you could create new tables, with new column names (conforming to your new naming standards!!) and create a VIEW with the original table name, and the original column names, so that legacy code will still work.

Legacy code will, however, need to "wrap" the illegal column names in square brackets - e.g.

SELECT [1 Bad Column name] FROM [My Bad TableName]

So something like

CREATE VIEW [My Bad TableName]
AS
SELECT My_New_ColumnName_1 AS [1 Bad Column name],
...
FROM My_New_TableName

The real issue is probably choosing a method that a) keeps the existing legacy stuff happy and b) allows you to move forwards with the benefit of hindsight and your new-found experience!

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-28 : 06:22:17
Well Kris. Where were you for two weeks? Busy in work or enjoying holidays?

Madhivanan

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

Kristen
Test

22859 Posts

Posted - 2005-12-28 : 10:57:46
Sat on a beach. Well, except for when I was snorkelling around just off the beach! Of course I was never to be found in the bar ... oh no, not me!

Kristen
Go to Top of Page
   

- Advertisement -