数据字典例子 转自csdn
create table datadict(tablename varchar(20),cloname varchar(20),colnote varchar(20),conshow int,consort int)
insert into datadict select 't_product_list','listid','产品标识',1,2
insert into datadict select 't_product_list','pname','产品名称',1,1
insert into datadict select 't_product_list','ptype','产品类型',0,3
insert into datadict select 't_product_list','psource','产品来源',0,4
insert into datadict select 't_user','userid','产品标识',1,1
insert into datadict select 't_user','username','用户名称',1,2
insert into datadict select 't_user','userage','用户年龄',1,3
insert into datadict select 't_user','user***','用户性别',0,4
create table t_product_list(listid int,pname varchar(20),ptype varchar(20),psource varchar(20))
insert into t_product_list select 1,'茶叶','日用品', '仓库一'
insert into t_product_list select 2,'鞋子', '日用品' , '仓库二'
insert into t_product_list select 3,'帽子', '日用品' , '仓库三'
declare @sql varchar(1000)
set @sql=''
select @sql=@sql+','+colnote+'='+cloname
from datadict where tablename='t_product_list' and conshow=1
set @sql='select '+stuff(@sql,1,1,'')+' from t_product_list'
exec(@sql)
--排序的
declare @tn varchar(50),@b int ,@e int,@sql varchar(1000)
select @tn = 't_product_list',@b= 1,@e = 2
select @sql = isnull(@sql+',','')+colnote+'='+cloname from datadict
where tablename = @tn and consort between @b and @e order by consort
set @sql = 'select '+@sql+' from '+@tn
exec(@sql)
English Version
create table datadict(tablename varchar(20),cloname varchar(20),colnote varchar(20),conshow int,consort int)
insert into datadict select 't_product_list','listid','ptag',1,2
insert into datadict select 't_product_list','pname','pname',1,1
insert into datadict select 't_product_list','ptype','ptype',0,3
insert into datadict select 't_product_list','psource','psource',0,4
insert into datadict select 't_user','userid','ptag',1,1
insert into datadict select 't_user','username','uname',1,2
insert into datadict select 't_user','userage','uage',1,3
insert into datadict select 't_user','user***','ugender',0,4
create table t_product_list(listid int,pname varchar(20),ptype varchar(20),psource varchar(20))
insert into t_product_list select 1,'tea','gro1', 'warehouse1'
insert into t_product_list select 2,'shoe', 'gro1' , 'warehouse2'
insert into t_product_list select 3,'hat', 'gro1' , 'warehouse3'
declare @sql varchar(1000)
set @sql=''
select @sql=@sql+','+colnote+'='+cloname from datadict where tablename='t_product_list' and conshow=1
--print @sql
set @sql='select '+stuff(@sql,1,1,'')+' from t_product_list'
print @sql
exec(@sql)
select ptag=listid,pname=pname from t_product_list
select * from t_product_list
--排序的
declare @tn varchar(50),@b int ,@e int,@sql varchar(1000)
select @tn = 't_product_list',@b= 1,@e = 2
select @sql = isnull(@sql+',','')+colnote+'='+cloname from datadict
where tablename = @tn and consort between @b and @e order by consort
set @sql = 'select '+@sql+' from '+@tn
print @sql
exec(@sql)
0 Comments:
Post a Comment
<< Home