sql 使用中的表可以修改字段类型吗

2025-04-26 07:34:31
推荐回答(2个)
回答1:

/*判断该表是否已经存在*/
if exists ( select * from sys.objects where name ='表名')
print '表存在'
else
print '表不存在'

if exists(select * from syscolumns where name='字段名' and id=object_id('表名'))
print '字段名存在'
else
print '字段名不存在'
--修改表字段类型
ALTER TABLE 表名 ALTER COLUMN 字段名 数据类型
ALTER TABLE User ALTER COLUMN name varchar(150)

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[存储过程名]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[存储过程名] --删除存储过程

回答2:

可以修改,但是不建议