第一,第二不是递增的,是一个string 数组 上面我只是一个例子,代表一个字符串,
表B 
主键  字段1  表A的主键 
1    第一次    1 
2      第二次    1 
3      第三次    1 
4      第四次      1 
其中表A的主键是表B中的一个字段,和表A相关联,表B中只要三个字段分别为 主键,字段1, 表A的主键

解决方案 »

  1.   

    先将数组分拆成多个数据:
    --test declare @str varchar(200)select @str='111,222,333'
    select *from  f_splitSTR(@str,',')declare @a table(id int identity(1,1),t varchar(20))
    declare @b table(id int identity(1,1),t varchar(20),aid int )insert into @a select @str
    insert into @b(t,aid)
    select *,1 from  f_splitSTR(@str,',')
    --分拆的字符串为一个数据表
    CREATE FUNCTION f_splitSTR(
    @s   varchar(8000),   --待分拆的字符串
    @split varchar(10)     --数据分隔符
    )RETURNS @re TABLE(col varchar(100))
    AS
    BEGIN
    DECLARE @splitlen int
    SET @splitlen=LEN(@split+'a')-2
    WHILE CHARINDEX(@split,@s)>0
    BEGIN
    INSERT @re VALUES(LEFT(@s,CHARINDEX(@split,@s)-1))
    SET @s=STUFF(@s,1,CHARINDEX(@split,@s)+@splitlen,'')
    END
    INSERT @re VALUES(@s)
    RETURN
    END
    GO
      

  2.   

    if object_id('ta') is not null
    drop table ta
    go
    if object_id('tb') is not null
    drop table tb
    go
    create table ta(id int identity(1,1),s varchar(50))
    create table tb(id int identity(1,1),aid int,s varchar(50))
    go
    create trigger tri_name
    on ta
    for insert
    as
    begin
    ;with t as (
    select distinct id,b.x from 
    (select id,cast('<items><item>'+replace(s,',','</item><item>')+'</item></items>' as xml) as x from inserted)a
    cross apply
    (select x=t.x.value('text()[1]','varchar(50)') from a.x.nodes('//item') as t(x))b
    )
    insert into tb (aid,s)
    select id,x from t
    endinsert into ta(s) select '第一次,第二次,第三次'
    select * from tbid aid s
    1 1 第二次
    2 1 第三次
    3 1 第一次