Create table my_status (status_id int NOT NULL AUTO_INCREMENT,status_type varchar(20), PRIMARY KEY (status_id));
去创造
insert into my_status (status_type) values("Single"),("Divorced"),("Married");
插入
您的第二个问题的可能答案
CREATE TABLE `my_status` (
`status_id` int(11) NOT NULL auto_increment,
`status_type` varchar(30),PRIMARY KEY(`status_id`) );
CREATE TABLE `my_profession` (
`profession_id` int(11) NOT NULL auto_increment,
`profession_type` varchar(30),PRIMARY KEY(`profession_id`) );
CREATE TABLE `my_contacts` (
`id` int(11) NOT NULL auto_increment,
`last_name` varchar(30) ,
`first_name` varchar(20) ,
`email` varchar(50) ,
`gender` char(1),
`birthday` date ,
`profession_id` int(11),
`location` varchar(50),
`status_id` int(11),
`interests` varchar(200),
`seeking` varchar(200),
PRIMARY KEY (`id`),
FOREIGN KEY (status_id)
REFERENCES my_status(status_id),
FOREIGN KEY (profession_id)
REFERENCES my_profession(profession_id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
insert into my_status (status_type) values("Single"),("Divorced"),("Married");
insert into my_profession (profession_type) values("Writer"),("CA"),("Developer");
INSERT INTO `my_contacts` (`last_name`,`first_name`,`email`,`gender`,`birthday`,`profession_id`,`location`,`status_id`,`interests`,`seeking`) VALUES ('Anderson','Jillian','jill_anderson@ \nbreakneckpizza.com','F','1980-09-05',1,'Palo Alto, CA',1,'kayaking, reptiles','relationship, friends');
INSERT INTO `my_contacts` (`last_name`,`first_name`,`email`,`gender`,`birthday`,`profession_id`,`location`,`status_id`,`interests`,`seeking`) VALUES ('Kenton','Leo','lkenton@starbuzzcoffee.com','M','1974-01-10',2,'San Francisco, CA',2,'women','women to date');
INSERT INTO `my_contacts` (`last_name`,`first_name`,`email`,`gender`,`birthday`,`profession_id`,`location`,`status_id`,`interests`,`seeking`) VALUES ('McGavin','Darrin',' captainlove@headfirsttheater.com','M','1966-01-23',3,'San Diego, CA',3,'sailing, fishing, yachting','women for casual relationships');
INSERT INTO `my_contacts` (`last_name`,`first_name`,`email`,`gender`,`birthday`,`profession_id`,`location`,`status_id`,`interests`,`seeking`) VALUES ('xyz','abc',' xyz@abc.com','F','1966-01-24',1,'San Diego, CA',3,'sailing, fishing, yachting, golfing','women for casual relationships');
select * from my_contacts;
select * from my_status;
select * from my_profession;
SELECT * FROM my_contacts WHERE status_id IN
(SELECT status_id FROM my_status WHERE status_type = 'Married');
希望这是你想要的!!!