1。就是想用一条语句插入查到的所有记录: INSERT INTO tbl_person(person_id)values(
   SELECT person_id FROM tbl_user  where login_id = 'xxxx'
)是这样吗?2。我想问下爪子图 1对(0或1个)什么意思,下面这个爪子图怎么画啊?
一个account_id 只能有 一个person_id 但是 一个person_id 可以有多个account_id?
我这么画对吗?

解决方案 »

  1.   


    INSERT INTO tbl_person(person_id) SELECT person_id FROM tbl_user  where login_id = 'xxxx'
      

  2.   

    darlingdd (darlingdd)
      '截至2010-11-02 22:41:12  用户结帖率45.45%当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
    http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
    http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html8、如何给分和结贴?
    http://community.csdn.net/Help/HelpCenter.htm#结帖
      

  3.   

    1:
    INSERT INTO tbl_person(person_id)
    SELECT person_id FROM tbl_user  where login_id = 'xxxx'这样就可以了2:
    这和数据库范式差不多,你可以去看下相关资料.
      

  4.   

    1:
    INSERT INTO tbl_person(person_id) SELECT person_id FROM tbl_user  where login_id = 'xxxx'
      

  5.   

    那么请问:INSERT INTO tbl_person(person_id,item_name) values(SELECT person_id FROM tbl_user  where login_id = 'xxxx','这个Item_name是个固定字串!') 
    如何写?
    感谢!
      

  6.   

    新加个扩展,已被不时之需,呵呵
    C:\Program Files\PostgreSQL\9.0\bin>psql -U postgres
    psql (9.0.1)
    Type "help" for help.postgres=# create TEMP table ttt(stu_name varchar(10),item_id int);
    CREATE TABLE
    postgres=# select * from ttt;
     stu_name | item_id
    ----------+---------
    (0 rows)
    postgres=# \d stu_info
                                          Table "public.stu_info"
        Column    |            Type             |                       Modifiers
    --------------+-----------------------------+-------------------------------------------------------
     stu_id       | integer                     | not null default nextval('stu_info_id_seq'::regclass)
     stu_name     | character varying(16)       | not null
     sex          | character(1)                |
     grade        | character varying(16)       |
     class        | character varying(8)        |
     birthday     | timestamp without time zone |
     address      | character varying(64)       |
     parents_name | character varying(16)       |
     phone        | character varying(32)       |
     notes        | character varying(128)      |
     entery_date  | timestamp without time zone | default ('now'::text)::date
    Indexes:
        "stu_info_pkey" PRIMARY KEY, btree (stu_id)
    Referenced by:
        TABLE "stu_exam_score" CONSTRAINT "stu_exam_score_id_fk" FOREIGN KEY (stu_id) REFERENCES stu_info(stu_id) ON UPDATE CASCADE ON DELETE CASCADE
    postgres=# insert into ttt(stu_name) select stu_name from stu_info limit 5;
    INSERT 0 5
    postgres=# select * from ttt;
     stu_name | item_id
    ----------+---------
     谷金洲   |
     张大伟   |
     乔楷立   |
     赵鹤予   |
     张跃天   |
    (5 rows)
    postgres=# insert into ttt(stu_name,item_id) values(select stu_name from stu_info limit 5,888);
    ERROR:  syntax error at or near "select"
    第1行insert into ttt(stu_name,item_id) values(select stu_name fro...
                                                  ^
    postgres=# insert into ttt(stu_name,item_id) select stu_name,888 from stu_info limit 5;
    INSERT 0 5
    postgres=# select * from ttt;
     stu_name | item_id
    ----------+---------
     谷金洲   |
     张大伟   |
     乔楷立   |
     赵鹤予   |
     张跃天   |
     谷金洲   |     888
     张大伟   |     888
     乔楷立   |     888
     赵鹤予   |     888
     张跃天   |     888
    (10 rows)
    postgres=# alter table ttt add column item_name varchar(64);
    ALTER TABLE
    postgres=# insert into ttt(stu_name,item_name) select stu_name,'This is a StaticString' from stu_info limit 5;
    INSERT 0 5
    postgres=# select * from ttt;
     stu_name | item_id |       item_name
    ----------+---------+------------------------
     谷金洲   |         |
     张大伟   |         |
     乔楷立   |         |
     赵鹤予   |         |
     张跃天   |         |
     谷金洲   |     888 |
     张大伟   |     888 |
     乔楷立   |     888 |
     赵鹤予   |     888 |
     张跃天   |     888 |
     谷金洲   |         | This is a StaticString
     张大伟   |         | This is a StaticString
     乔楷立   |         | This is a StaticString
     赵鹤予   |         | This is a StaticString
     张跃天   |         | This is a StaticString
    (15 rows)[