//用游标遍历表tab_jl来创建子表
string sqltext2="declare @id int; declare pcurr cursor for select JL_ID from tab_jl;"; //定义变量id和游标pcurr,
sqltext2+="open pcurr; fetch next from pcurr into @id ;"; //这段程序中有两张表,其中tab_jl是总表,我的想法是根据JL_ID遍历tab_jl
sqltext2+="while (@@fetch_status = 0)"; //如果tab_jl中GY_GYWF(是子表的表名)在数据库中没有,就create一张
sqltext2+="begin;";
sqltext2+="if not exists(Select name from sysobjects where name=(Select tab_jl.JL_GYWF from tab_jl where tab_jl.JL_ID=id))"; //还有这一步有没有错?
sqltext2+="create table tab_jl.JL_GYWF(T int not null identity,GY_DWBZ bit,GY_FXMS varchar(50);";
sqltext2+="fetch next from pcurr into @id;";
sqltext2+="end;";
sqltext2+="close pcurr;";
sqltext2 += "deallocate pcurr;";
应该有不少问题,望指正。
string sqltext2="declare @id int; declare pcurr cursor for select JL_ID from tab_jl;"; //定义变量id和游标pcurr,
sqltext2+="open pcurr; fetch next from pcurr into @id ;"; //这段程序中有两张表,其中tab_jl是总表,我的想法是根据JL_ID遍历tab_jl
sqltext2+="while (@@fetch_status = 0)"; //如果tab_jl中GY_GYWF(是子表的表名)在数据库中没有,就create一张
sqltext2+="begin;";
sqltext2+="if not exists(Select name from sysobjects where name=(Select tab_jl.JL_GYWF from tab_jl where tab_jl.JL_ID=id))"; //还有这一步有没有错?
sqltext2+="create table tab_jl.JL_GYWF(T int not null identity,GY_DWBZ bit,GY_FXMS varchar(50);";
sqltext2+="fetch next from pcurr into @id;";
sqltext2+="end;";
sqltext2+="close pcurr;";
sqltext2 += "deallocate pcurr;";
应该有不少问题,望指正。
sqltext2+="open pcurr; fetch next from pcurr into @id ;"; //这段程序中有两张表,其中tab_jl是总表,我的想法是根据JL_ID遍历tab_jl
sqltext2+="while (@@fetch_status = 0)"; //如果tab_jl中GY_GYWF(是子表的表名)在数据库中没有,就create一张
sqltext2+="begin";
sqltext2+="if not exists(Select name from sysobjects where name=(Select tab_jl.JL_GYWF from tab_jl where tab_jl.JL_ID=@id))"; //还有这一步有没有错?
sqltext2+="create table [tab_jl.JL_GYWF](T int not null identity,GY_DWBZ bit,GY_FXMS varchar(50));";
sqltext2+="fetch next from pcurr into @id;";
sqltext2+="end";
sqltext2+="close pcurr;";
sqltext2 += "deallocate pcurr;";
sqltext2+=" begin ";
sqltext2+=" end ";