//用游标遍历表tab_jl并创建子表 string sqltext2="declare @JL_ID int; declare pcurr cursor for select JL_ID from tab_jl;"; //定义变量JL_ID和游标pcurr, sqltext2+="open pcurr; fetch next from pcurr into @JL_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=JL_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 @JL_ID;"; sqltext2+="end;"; sqltext2+="close pcurr;"; sqltext2 += "deallocate pcurr;"; 上面的代码麻烦哪位大侠看一下,看标点有没有问题,还有逻辑对不对。
不用,MSSQL也能认得.
//用游标遍历表tab_jl并创建子表
string sqltext2="declare @JL_ID int; declare pcurr cursor for select JL_ID from tab_jl;"; //定义变量JL_ID和游标pcurr,
sqltext2+="open pcurr; fetch next from pcurr into @JL_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=JL_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 @JL_ID;";
sqltext2+="end;";
sqltext2+="close pcurr;";
sqltext2 += "deallocate pcurr;";
上面的代码麻烦哪位大侠看一下,看标点有没有问题,还有逻辑对不对。
end
以及end的前一语句,不要加分号.