Confused about creating a table in mysql -


i found question on stackoverflow asked on year ago similar database structure in mysql. questions found here

the answer has been provided makes sense except following table:

message_type: message_type_id, description (1:public, 2:friends, 3:specific_recipients) 

can me figure out how create table implements (1:public, 2:friends, 3:specific_recipients) property please?

edit

user: user_id, given_name, ...  message: message_id, owner_id (fk user), subject, body, posted, message_type_id (fk message_type)...  message_recipients: user_id (fk user), message_id (fk message)  message_type: message_type_id, description (1:public, 2:friends, 3:specific_recipients) 

so tried implementing database based on having problem setting up. first problem: message table has fk called message_type_id if @ previous op's question, field called ispublic , not pk. how change ispublic field fk without deleting records. need specify updates or alter conditions while creating tables.

it looks me message_type has 2 columns message_type_id , description , contains 3 rows containing values in brackets, this:

message_type_id | description ----------------+-------------------- 1               | public 2               | friends 3               | specific_recipients 

there few ways write sql this, 1 way (with message_type_id primary key):

create table message_type (message_type_id int not null primary key,                            description varchar(100)) select 1 message_type_id, 'public' description union select 2, 'friends' union select 3, 'specific_recipients' 

see this more.

or:

create table message_type (message_type_id int not null primary key,                            description varchar(100));  insert message_type values (1, 'public'), (2, 'friends'), (3, 'specific_recipients') 

edit question edit:

if have created message table (for example):

create table message (   message_id int(10) unsigned not null auto_increment,   ispublic tinyint(4) default '0',   primary key (message_id) ); 

this replace (a presumably boolean) ispublic message_type_id:

alter table message add column message_type_id int references message_type(message_type_id);  # classified that's not public friends update message set message_type_id = case when ispublic = 1 1                            else 2                       end;  alter table message drop column ispublic; 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -