大家帮下忙,如图这是一个数据库设计的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期望的结果不用描述了吧,不能把字段描述省掉了哦
首先要将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期望的结果不用描述了吧,不能把字段描述省掉了哦
解决方案 »
- 如何实现多条记录的某个字段合成一个段 作为一条记录显示。
- sql数据库表的设计问题
- sql server 并发的实现机制谁能说一说啊~还有操作的优先级
- 很简单的问题,关于一个类别查询的问题,
- 求一个SQL语句
- 求一取随机数的存储过程或函数!
- 见文章内容中的SQL语句,如果把Insert Into 拿掉,结果出来只要3秒,可把Insert Into开起来就要36秒,是什么原因啊?
- 我在2000 SERVER上安装SQL Server7.0总是失败,为什么呢?很着急!!!
- DELPHI5中连结SQL Server2000数据库出错,请大家帮忙!谢谢!
- 急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急!
- 新手问题 帮忙解决下
- sql 查询 统计
我能看到
http://hi.baidu.com/%C6%AE%C3%EC%B5%C4%C4%BE%CD%B7%C8%CB/album/item/875df8ee3301947e79f05524.html
根据这些信息建个存储过程 建表
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
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
应该是百度有限制的,你删除cookie后再来看这个贴子就知道了,记得不要登录百度直接过来看,~~