使用SQL SERVER修改表中的现有列 [英] modify existing column in an table using SQL SERVER

查看:100
本文介绍了使用SQL SERVER修改表中的现有列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的桌子上有10条记录.我想用标识修改表列

喜欢,

ALTER TABLE ALTER COLUMN整数标识(10,1)
表中已经插入了10个值.

我的错误:
关键字"IDENTITY"附近的语法不正确.

I Have 10 records in my table. i want to modify the table column with identity

like,

ALTER TABLE ALTER COLUMN INT IDENTITY (10, 1)
Already 10 Values are inserted in Table.

My Error:
Incorrect syntax near the keyword ''IDENTITY''.

推荐答案

Alter Table Names
Add Id_new Int Identity(10, 1)
Go

Alter Table Names Drop Column ID
Go

Exec sp_rename 'Names.Id_new', 'ID', 'Column'



请检查.
http://stackoverflow.com/questions/1049210/adding-an-identity- to-an-existing-column [ ^ ]



Please check.
http://stackoverflow.com/questions/1049210/adding-an-identity-to-an-existing-column[^]


您忘记了列名-它应该在单词"COLUMN"和"INT"之间
You forgot the column name - it should be between the words "COLUMN" and "INT"


删除旧列并添加新列.
Remove the old column and add new one.
--SQL Script:
ALTER TABLE Users DROP PK_Users
GO
ALTER TABLE Users DROP COLUMN UserID
GO
ALTER TABLE Users ADD UserID int NOT NULL IDENTITY(1,1) 
GO
ALTER TABLE Users ADD CONSTRAINT PK_Users PRIMARY KEY CLUSTERED ([UserID] ASC)
GO


这篇关于使用SQL SERVER修改表中的现有列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆