CREATE TABLE NewTable (column_a INT)
GO
ALTER TABLE NewTable ADD column_b VARCHAR(20) NULL
GO
重复上面步骤
GO
ALTER TABLE NewTable ADD column_b VARCHAR(20) NULL
GO
重复上面步骤
解决方案 »
- 与企业的合作项目用sql server 2000 开发版是否靠谱?
- 无法打开到主机的连接 在端口 1433 : 连接失败
- 数据库中时间 一开始为null 然后update set sj='8:00:00'怎么全变成1900-1-1 8:00:00
- 怎么查询最新日期
- 有些机子能连sql,有些就提示不存或访问被拒绝???
- excel的float类型导入到sql server 2000时不能转换成datetime
- 请问如何传递参数给视图?
- SQL2005安装与.NET framework冲突问题
- 编程技术论坛主页交换连接!!!
- 请问这样的SQL语句怎么写?
- sqlsever2000里保存是big5,分析器查询是big5,但用PB提取出来却变成了乱码
- 数据库管理系统对于使用用户如何来分开对待?
declare #tb cursor for select distinct ename from 数据结构表
open #tb
fetch next from #tb into @fdname
while @@fetch_status<>0
begin
set @sql='create table ['+@fdname+'](字段名 int)'
exec(@sql)
fetch next from #tb into @fdname
end
close #tb
deallocate #tb
set @sql=''
select @sql=@sql+char(13)+'create table ['+ename +'](字段名 int)'
from(select distinct ename from 数据结构表) a
exec(@sql)
我是要建一张表,表的字段名是[数据结构表]中eName字段的记录值,现在有20条记录,也就是说新表有20个字段
set @sql='create table 表名('
select @sql=@sql+'['+ename +'] int,' --如果不是int,就将它改成其他类型
from(select distinct ename from 数据结构表) a
set @sql=left(@sql,len(@sql)-1)+')'
exec(@sql)
我还忘了说一个问题:当我从表中取出eName的记录值时,有个要求是parient_id字段等于1的eName记录值,所以我定义的游标是
declare #tb cursor for select distinct eName from [dbo].[数据结构表] where parient_id=1
应该是你写的语句有错,贴出来看看.
记录不多的话,不用游标好一点,用我的这个方法试试:
declare @sql varchar(8000)
set @sql='create table 表名('
select @sql=@sql+'['+ename +'] int,' --如果不是int,就将它改成其他类型
from(select distinct ename from 数据结构表 where parient_id=1) a
set @sql=left(@sql,len(@sql)-1)+')'
exec(@sql)
As
declare @tbname varchar(10)
declare @fdname varchar(10)
declare @pd integer,@cd integer
declare sCursor cursor for select eName,parient_id from [dbo].[数据结构表]
declare @sql varchar(8000)
declare tb cursor for select distinct eName from [dbo].[数据结构表] where parient_id=1
Open sCursor
fetch next from sCursor into @tbname,@pd
while @@fetch_status=0
begin
if @pd=0 break
fetch next from sCursor into @tbname,@pd
end
close sCursor
deallocate sCursor open tb
set @sql='create table '+@tbname+'( '
fetch next from tb into @fdname
while @@fetch_status<>0
begin
set @sql=@sql+' ['+@fdname+'] varchar(1000) Not null,'
fetch next from #tb into @fdname
end
close tb
begin
set @sql=@sql+' ['+@fdname+'] varchar(1000) Not null,'
fetch next from #tb into @fdname --这里的#tb是从那里来的?你没有定义这个游标吧?
end
close tb
set @sql=@sql+' ['+@fdname+'] varchar(1000) Not null,'
fetch next from tb into @fdname --根据你的要求,应该是这样的.
end
close tb
在open tb之前有这么一句:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[@tbname]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
exec('drop table'+' [dbo].['+@tbname+']')
declare @i varchar(255)
open cursor_insert
fetch cursor_insert into @i
while @@fetch_status=0
begin
exec('create table ['+@fdname+'](字段名 int,其他字段 int)')
fetch cursor_insert into @i
end
close cursor_insert
deallocate cursor_insert
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].['+@tbname+']') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
exec('drop table'+' [dbo].['+@tbname+']')
而不是真正要检查的表.(误将变量放入了字符串中)
from(select distinct ename from 数据结构表 where parient_id=1) a
能给我解释一下这句中的a做什么用的吗
警告: 已创建表 'Jgzdml',但其最大行大小(11250)超过了每行的最大字节数(8060)。如果结果行长度超过 8060 字节,则此表中行的 INSERT 或 UPDATE 将失败。我开始已经执行了一次定义为1000的,然后该了执行就出现上面的错
create proc btable @tbname varchar(10) output
为什么我执行的时候出现这个问题呢?
过程 '建基础表' 需要参数 '@tbname',但未提供该参数。
exec btable @re out --输入参数
print @re --显示存储过程返回结果.