Reputation: 157
I'm just wondering if it is OK to used the email address as a Table in SQL script? for example,
select distinct usr.user_name as USER_NAME, usr.id as USER_ID
from [email protected] usr, [email protected] -- <-----------------------
where usr.id = ua.id
group by usr.name, usr.id;
My problem is that, I received the log file containing the error of the script and I noticed that the table used is email address. So, my assumption is that the caused of the error is in the table itself. Or, is it OK to use an email address as a lookup table in script?
Upvotes: 0
Views: 408
Reputation: 1271211
This is a bit long for a comment.
No, it is not all right to have a table name like [email protected]
, for the simple reason that .
and @
are not allowed as table names. So, any attempt to do:
from [email protected]
is going to result in a syntax error.
SQL does allow you to escape table names. You can get around this problem with one of these:
from "[email protected]"
from `[email protected]`
from [[email protected]]
(which depends on your database).
More importantly, though, is that there is no sensible reason (that I can think of) to have a table represent separate emails. Normally, email
would be a column in a table, not a table name.
So, you would have tables like:
Users
Table
userId userName email . . .
And UsersActivity
table:
userActivityId userId . . . .
email
would be a column in Users
, which you would look up using a JOIN
.
Upvotes: 1