Skip to content

Column name problems

MichelleTaylorRG edited this page Jun 19, 2019 · 1 revision

From http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/do-not-use-spaces-or-other-invalid-chara:

Column names (and table names) should not have spaces or any other invalid characters in them. This is considered bad practice because it requires you to use square brackets around your names. Square brackets make the code harder to read and understand. The query (presented below) will also highlight columns and tables with numbers in the names. Most of the time, when there is a number in a column name, it represents a de-normalized database. There are exceptions to this rule, so not all occurrences of this problem need to be fixed.

How to correct it: If this is a number issue, you may need to redesign your database structure to include more tables. For example, if you have a StudentGrade table with (StudentId, Grade1, Grade2, Grade3, Grade4) you should change it to be StudentGrade with (StudentId, Grade, Identifier). Each student would have multiple rows in this table (one for each grade). You would need to add an identifier column to indicate what the grade is for (test on November 10, book report, etc).

If this is a weird character issue, then you should change the name of the column so it is a simple word or phrase without any spaces, numbers, or symbols. When you do this, make sure you check all occurrences of where this is used from. This could include procedures, function, views, indexes, front end code, etc...

Clone this wiki locally