So I am reading a text on SQL to learn it.
These authors (and this may be specific to these authors, but also may be an important concept to understand) use a # sign after some fields. I cant understand why.
For example for a set of tables in an early example.
First line is Table Name the rest are fields, Further the only thing I changed was replacing a key symbol with (key) and there were boxes around them, but that's the sum of the information.
SECTIONS (table name)
course# (key)
section# (key)
teacher#
num_students
I am referring to course# and section# .Remaining tables: for completeness, but doesnt add anything.
ENROLLS
course# (key)
section# (key)
student# (key)
grade
TEACHERS
teacher# (key)
teacher_name
phone
salary
COURSES
course# (key)
course_name
department
num_credits
STUDENTS
student# (key)
student_name
address
city
state
zip
gender
The text is A Visual Introduction to SQL by David Chappell and J Harvey Trimble Jr.
I have a physical copy so I cant easily put up pictures.
I have thought- maybe these are 'numeric" fields but zip
is not zip#
, or maybe they are primary keys elsewhere- in their respective table. The example above I have all the tables shown.
disclaimer:
Its not explained in the text. Ive searched google, though forgive me if someone comes up with an easy a google result. YMMV obviously, and I have also searched here, and while I found a similar one, It dealt with prefixed '#' not postfixed #.
CodePudding user response:
They're using #
where literally everyone else would use Id
. CourseId
, SectionId
, etc. In most SQL implementations allow use of #
in a column name if you delimit it (e.g. [Course#]
). Don't do this. You will kick yourself every single day of using a database with garbage field names like that.
CodePudding user response:
In standard SQL #
is invalid in an identifier, but e.g. Oracle or DB2 do allow it (if it's not the first character) without the need to quote the identifier.
In my experience, it is usually used as an abbreviation for "number", so course#
is essentially a short way of writing course_number