Question: I have a table which stores comments, the comment can either come from another user, or another profile which are separate entities in this app. 

My original thinking was that the table would have both user\_id and profile\_id fields, so if a user submits a comment, it gives the user\_id leaves the profile\_id blank

is this right, wrong, is there a better way?

Answer: 
If the comments are general for several objects you could create a table for each object:

```
user_comments (user_id, comment_id)
profile_comments (profile_id, comment_id)

```

Then you do not have to have any empty columns in your comments table. It will also make it easy to add new comment-source-objects in the future without touching the comments table.
Here's another approach, which allows you to maintain referential integrity through foreign keys, manage centrally, and provide the highest performance using standard database tools such as indexes and if you really need, partitioning etc:

```
create table actor_master_table(
  type char(1) not null, /* e.g. 'u' or 'p' for user / profile */
  id varchar(20) not null, /* e.g. 'someuser' or 'someprofile' */
  primary key(type, id)
);

create table user(
  type char(1) not null,
  id varchar(20) not null,
  ...
  check (id = 'u'),
  foreign key (type, id) references actor_master_table(type, id)
);

create table profile(
  type char(1) not null,
  id varchar(20) not null,
  ...
  check (id = 'p'),
  foreign key (type, id) references actor_master_table(type, id)
);

create table comment(
  creator_type char(1) not null,
  creator_id varchar(20) not null,
  comment text not null,
  foreign key(creator_type, creator_id) references actor_master_table(type, id)
);

```