首页 新闻 会员 周边

mysql 两章表 两个字段怎么做?

0
悬赏园豆:20 [已解决问题] 解决于 2014-04-08 23:38

比如

//网络媒体信息表
    CREATE TABLE network_information(
    network_information_id int(4) not null primary key auto_increment,
    network_information_title_id int(4) not null default '0',
    network_information_content varchar(100) not null,
    network_information_date int(18) not null
            );
            +------------------------------+--------------+------+-----+---------+----------------+
        | Field                        | Type         | Null | Key | Default | Extra          |
        +------------------------------+--------------+------+-----+---------+----------------+
        | network_information_id       | int(4)       | NO   | PRI | NULL    | auto_increment |
        | network_information_title_id | int(4)       | NO   |     |  0      |                |
        | network_information_content  | varchar(100) | NO   |     | NULL    |                |
        | network_information_date     | int(18)      | NO   |     | NULL    |                |
        +------------------------------+--------------+------+-----+---------+----------------+
            
    CREATE TABLE network_information_title(
    network_information_title_id int(4) not null primary key auto_increment,
    network_information_id int(4) not null default '0',
    network_information_title varchar(50) not null
    );
        +------------------------------+-------------+------+-----+---------+----------------+
| Field                        | Type        | Null | Key | Default | Extra          |
+------------------------------+-------------+------+-----+---------+----------------+
| network_information_title_id | int(4)      | NO   | PRI | NULL    | auto_increment |
| network_information_id       | int(4)      | NO   |     | 0       |                |
| network_information_title    | varchar(50) | NO   | UNI | NULL    |                |
+------------------------------+-------------+------+-----+---------+----------------+

            // 添加唯一约束索引
            ALTER TABLE network_information_title ADD unique(network_information_title);
INSERT IGNORE INTO abroad_information_title(abroad_information_title) VALUES ('这是一个示范');
我创建两个表,我存数据时,把名字存到network_information_title表里,这个属性唯一的,然后自动出现一个ID,
我我怎么把这个ID,和其他的数据存到另一张表呢,比如内容,能用一条语句作么?要效率好的,谢谢了,麻烦了,我是菜鸟,
请说的详细点,谢谢了
庆小伟的主页 庆小伟 | 初学一级 | 园豆:125
提问于:2014-04-08 18:02
< >
分享
最佳答案
1

一句语句我不知道怎么做,我也是菜鸟,我只知道mysql里有个LAST_INSERT_ID()可以帮到你,你可以用它取得刚刚插入的id.如果你希望做在"一个语句"里,我建议用mysql的存储过程来实现。

推荐用navicat这个工具来写mysql的程序。

本菜鸟只能帮到您这里了。

收获园豆:20
酱油能 | 菜鸟二级 |园豆:386 | 2014-04-08 21:42

我又看到您了,本菜鸟不值得用您这个贵称,linux ,fedora 下用什么mysql 语句。。。存储过程是吧,我看看去,谢谢了哈

庆小伟 | 园豆:125 (初学一级) | 2014-04-08 23:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册