大家帮下忙,如图这是一个数据库设计的Execl文档我想用存储过程把根据这些信息建表,省点事,提高点效率
首先要将Execl文档的信息存到数据库表中,这一步我已经搞好了 if object_id('tb') is not null 
drop table tb
go
create table tb(id int not null identity(1,1) primary key ,
                表名 varchar(50),
                字段名称 varchar(50),
                字段描述 varchar(100),
                字段类型 varchar(50),
                长度 int,
                主键否 varchar(2),
                空值验证 varchar(5))
go
insert into tb select 'moa_user', 'user_id', '用户ID', 'varchar', '50','是', '非空'
insert into tb select 'moa_user', 'user_name', '用户名称', 'varchar', '30','否', '非空'
insert into tb select 'moa_user', 'user_is_visible', '是否注销', 'tinyint', '1','否', '空'
insert into tb select 'moa_user', 'user_is_admin', '是否管理员', 'tinyint', '1','否', '空'
insert into tb select 'moa_user', 'user_password', '用户密码', 'varchar', '16','否', '非空'
insert into tb select 'moa_user', 'user_create_date', '用户创建日期', 'datetime', '8','否', '空'
insert into tb select 'moa_department', 'department_id', '部门ID', 'int', '4','是', '非空'
insert into tb select 'moa_department', 'department_name', '部门名称', 'varchar', '30','否', '非空'
insert into tb select 'moa_permission', 'permission_id', '权限ID', 'int', '4','是', '非空'
insert into tb select 'moa_permission', 'permission_name', '权限名称', 'varchar', '30','否', '非空'
insert into tb select 'moa_permission', 'permission_description', '权限描述', 'varchar', '-1','否', '非空'
insert into tb select 'moa_permission', 'permission_enum_string', '权限缩写码', 'varchar', '30','否', '非空'
insert into tb select 'moa_role', 'role_id', '角色编号', 'int', '4','是', '非空'
insert into tb select 'moa_role', 'role_name', '角色名称', 'varchar', '30','否', '空'
insert into tb select 'moa_role', 'role_description', '角色描述', 'varchar', '-1','否', '空'
insert into tb select 'moa_department_user', 'department_id', '部门ID', 'int', '4','否', '非空'
insert into tb select 'moa_department_user', 'user_id', '用户ID', 'varchar', '50','否', '非空'
insert into tb select 'moa_role_user', 'role_id', '角色ID', 'int', '4','否', '非空'
insert into tb select 'moa_role_user', 'user_id', '用户ID', 'varchar', '50','否', '非空'
goselect * from tb期望的结果不用描述了吧,不能把字段描述省掉了哦

解决方案 »

  1.   

    csdn不让传图片,我只好搞到百度去了,莫非你们没有权限查看
    我能看到
      

  2.   

    图片地址
    http://hi.baidu.com/%C6%AE%C3%EC%B5%C4%C4%BE%CD%B7%C8%CB/album/item/875df8ee3301947e79f05524.html
      

  3.   

    有语句呀,那些信息是我从execl中提取出来的 
    根据这些信息建个存储过程 建表
      

  4.   

    declare @tablename varchar(30)
    declare @sql varchar(8000)
    DECLARE cur_temp Cursor For 
    select distinct 表名 from [tb]
    OPEN cur_temp
    FETCH  cur_temp Into @tablename
    while @@fetch_status = 0 
    begin
    select @sql='drop table '+ @tablename
    exec(@sql)
    select @sql = ''
    select @sql=@sql+','+[字段名称]+' '+字段类型+case 字段类型 when 'varchar' then '('+ltrim(长度)+')' else '' end
    +case 主键否 when '是' then ' primary key ' else '' end+
    case 空值验证 when '非空' then ' not null' else ' null' end
    from tb where 表名 = 'moa_user'
    select @sql='create table '+@tablename+'('+stuff(@sql,1,1,'')+')'
    --print @sql
    exec(@sql) FETCH  cur_temp Into @tablename
    endClose     cur_temp
    Deallocate   cur_temp
      

  5.   

    --有个笔误
    declare @tablename varchar(30)
    declare @sql varchar(8000)
    DECLARE cur_temp Cursor For 
    select distinct 表名 from [tb]
    OPEN cur_temp
    FETCH  cur_temp Into @tablename
    while @@fetch_status = 0 
    begin
    select @sql='if object_id('''+@tablename+''') is not null drop table '+ @tablename
    exec(@sql)
    select @sql = ''
    select @sql=@sql+','+[字段名称]+' '+字段类型+case 字段类型 when 'varchar' then '('+ltrim(长度)+')' else '' end
    +case 主键否 when '是' then ' primary key ' else '' end+
    case 空值验证 when '非空' then ' not null' else ' null' end
    from tb where 表名 = @tablename
    select @sql='create table '+@tablename+'('+stuff(@sql,1,1,'')+')'
    --print @sql
    exec(@sql) FETCH  cur_temp Into @tablename
    endClose     cur_temp
    Deallocate   cur_temp
      

  6.   

    看不到图,,~~
    应该是百度有限制的,你删除cookie后再来看这个贴子就知道了,记得不要登录百度直接过来看,~~