Specifically, what is the significance of "AS Expr1"?
Basically, "Expr1" is an alias. Every object needs a name. When you create a calculated field in a query, if you don't name the "field", Access names that "field" using 'Expr" and a sequence number.
In this case, the calculation is concatenation of two table fields and some text. I didn't name the field, so Access did. The alias can be almost anything, but not existing field names, reserved words, etc.
(BTW, calculations in queries is GOOD, calculated fields in tables is BAD.)
Try this: change the name from "Expr1" to "Bananas".
Code:
SELECT tblSchools.SchoolID_PK, [SchoolName] & "- " & [SchoolState] AS Bananas FROM tblSchools ORDER BY [SchoolName] & "- " & [SchoolState];
Create a new query, switch to SQL view and paste in the above SQL. Execute the query. What is the field name?
Tables can also have aliases. Try this
Code:
SELECT S.SchoolID_PK, [SchoolName] & "- " & [SchoolState] AS B FROM tblSchools S ORDER BY [SchoolName] & "- " & [SchoolState];
Aliases are useful if you become excessively wordy. Say you named a table "tblElementary_Schools_in_Area_51".Your SQL would look like
Code:
SELECT tblElementary_Schools_in_Area_51.SchoolID_PK, tblElementary_Schools_in_Area_51.SchoolAddress, tblElementary_Schools_in_Area_51.SchoolState, [SchoolName] & "- " & [SchoolState] AS Bananas FROM tblElementary_Schools_in_Area_51 ORDER BY [SchoolName] & "- " & [SchoolState];
You could use the table alias to reduce the amount of typing
Code:
SELECT X.SchoolID_PK,S .SchoolAddress, X.SchoolState, [SchoolName] & "- " & [SchoolState] AS B FROM tblElementary_Schools_in_Area_51 X ORDER BY [SchoolName] & "- " & [SchoolState];
-------------------------------------------------------------
This allows the table to store the data as a number, but the form displays the text string associated with that number. In your opinion, is it better for the table to have it stored as a number vs. text?
This is part of the power of a RDBMS. If you normalize the table structure, you won't (shouldn't) duplicate data. (have the dame data n many tables)
Look at the teachers info table that has the teacher info AND the school info. Is the school name an attribute of a teacher?
This is called normalization. Teacher info (things about the teacher) goes in one table, school info goes into its own table.
You set up a relationship between the two tables, using a PK field and an FK field (1 to many). You only need one extra field (the FK field) in the teacher table instead of 6 fields for the school info. If you have 20 teachers working for a school and the school name changes from "Public School #10" to "Smithville School", you change the name once (in the school table) instead of having to change the name 20 times.... or maybe 50 times depending on how long the school has been open and how many teachers have worked there.
Some people use text fields as the PK/FK fields. I never do - see the link about Primary Key Tips and Techniques in post #4.
Also see the attached text file with links about normalization....