-1

也许我在想这是这些说明

创建四个新表:my_interests、my_professions、my_seeking 和 my_status。这些表应包含两列:一列用于 id,另一列用于数据值。从 my_contacts 表中的相应列填充这些。准备好新表后,您可以将原始数据列替换为与新 my_professions 和 my_status 表中适用的 id 值匹配的 id 号。

所以我读第一个的方式是我有第一个 col 作为自动增量主键,下一个值将是数据类型,我首先从 MY_STATUS 开始,类型将是

COMMITED_RELATIONSHIP

离婚

已婚

单身的

并且我的 AUTO_INC 编号将对应于数据的 ID,换句话说

01**承诺

02**离婚

03** 等等

我阅读说明的方式是否正确?如果不太确定如何执行此操作,我知道如何创建表,并且我了解插入和值,但我如何插入值和自动增量?我真的不喜欢编程:(

提前致谢

4

3 回答 3

0

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');

希望这是你想要的!!!

于 2013-10-31T11:49:33.273 回答
0
UPDATE my_contacts
 SET status='1'
 WHERE status='committed relationship';
    UPDATE my_contacts
    set status= '2'
    where status='divorced';
        UPDATE my_contacts
        set status= '3'
        where status='married';
            UPDATE my_contacts
            set status= '4'
            where status='single';
                UPDATE my_contacts
                set status= '5'
                where status='widowed';

感谢大家!!(是的,那次我大喊,大声笑!)

于 2013-10-31T14:15:33.870 回答
0

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");插入

于 2013-10-31T07:34:42.820 回答