修改表--如何用sql语句设置字段可取空值

whiteluobo 2003-07-16 05:36:44
在sqlserver7.0中,现在需要将所用sysobject.xtype="U"的表里面的所有列的属性都设置为可以为空值,请问如何用sql语句实现
...全文
539 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
whiteluobo 2003-07-17
  • 打赏
  • 举报
回复
痛苦, :(
楼上两位的办法都能够很好的将各个表的字段及其属性提取出来,但是
我还是不能将所选出的结果嵌套到alter table 语句里面。

不知道这个里面能不能够用到类似vf里面的宏操作?
whiteluobo 2003-07-17
  • 打赏
  • 举报
回复
非常感谢,我先试试。
啊呀 2003-07-17
  • 打赏
  • 举报
回复
UP
whiteluobo 2003-07-17
  • 打赏
  • 举报
回复
up
leimin 2003-07-16
  • 打赏
  • 举报
回复
use below T-sql script you can get table property:

select obj.name as tables,
col.name as columns,
stype.name as type,
col.length as length,
nullif(col.xprec,0) as precesion,
col.scale as scale,
case col.isnullable
when 1 then 'yes'
else 'no'
end as allownull,
col.colstat as identy

from sysobjects obj,
syscolumns col,
systypes as stype

where col.id = obj.id
and obj.xtype = 'U'

and col.xtype = stype.xtype
and stype.xtype = stype.xusertype
zjcxc 2003-07-16
  • 打赏
  • 举报
回复
--这个更详细一些,结果中:字段定义列包含了每个字段的简单定义,你再修改一下
select object_name(id) as 表名,c.name 字段名,t.name 字段类型名
,c.name +' '+t.name+
case when t.name in ('binary','char','nchar','nvarchar','varbinary','varchar')
then '('+cast(c.prec as varchar)+')'
when t.name in ('decimal','numeric')
then '('+cast(c.prec as varchar)+','+cast(c.scale as varchar)+')'
when t.name in ('bigint')
then ''
else '' end as 字段定义
from syscolumns c
inner join
systypes t
on c.xusertype=t.xusertype
where
c.status<>0x80
and c.name not in
(
'image','text','uniqueidentifier','sql_variant'
,'ntext','timestamp','sysname'
)
and objectproperty(id,N'IsUserTable')=1
zjcxc 2003-07-16
  • 打赏
  • 举报
回复
比较麻烦,你参数这个自己做修改吧:
--得到所有用户表的表名,字段名,数据类型和长度
select object_name(id) as 表名
,c.name as 字段名
,t.name 数据类型
,c.prec as 长度
from syscolumns c
inner join
systypes t
on c.xusertype=t.xusertype
where objectproperty(id,'IsUserTable')=1
whiteluobo 2003-07-16
  • 打赏
  • 举报
回复
确实有ALTER TABLE tablename 字段类型(字段长度) null 可以实现,但是我想取用的是sysobjects.xtype="U" 的所用表的所用字段,我怎么将字段类型和字段长度都提取出来呢?
littlechang 2003-07-16
  • 打赏
  • 举报
回复
alter table ....
whiteluobo 2003-07-16
  • 打赏
  • 举报
回复
自己up一下

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧