For queries that are not ad-hoc, you should always prefix each field with either the table name or the table alias, even if the field name is not ambiguous. This prevents the query from being interrupted later if someone adds a new column to one of the tables, which introduces ambiguity.
So that "id" and "name" are unique. But I still recommend calling the primary key something more specific than "id". In your example, I would use student_id and teacher_id . This helps prevent connection errors. In any case, you will need more specific names when starting tables with more than one unique key or multi-part keys.
It's worth thinking about it, but ultimately consistency may be a more important factor. I can handle tables built around id instead of student_id , but I'm currently working with an inconsistent schema that uses all of the following: id , sid , systemid and specific names like taskid . This is the worst of both worlds.
source share