十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
alter table tablename alter column [datatype]
尖扎网站建设公司创新互联,尖扎网站设计制作,有大型网站制作公司丰富经验。已为尖扎成百上千家提供企业网站建设服务。企业网站搭建\成都外贸网站制作要多少钱,请找那个售后服务好的尖扎做网站的公司定做!
比如我的表A中有个列叫 patientNo目前是int,我希望更改为varchar(50),不为空
alter table A alter patientNo varchar(50) not null
用update
set就可以了
update
表名
set
要修改的属性和值
如果你要修改具体的某列的某个属性可以在后面查出来用where
比如你说的a表中
id为1的数据中
b列下的值修改为2
update
a
set
b=2
where
id=1
使用脚本修改吧,界面也可以
脚本如下:
Alter table [表名] Alter column [列名] [列类型] [NOT NULL或者 NULL]
alter table 脚本很丰富,可以查看MS SQL的帮助,新手做baidu任务,给个满意吧
ALTER TABLE [ database_name . [ schema_name ] . | schema_name . ] table_name
{
ALTER COLUMN column_name
{
[ type_schema_name. ] type_name [ ( { precision [ , scale ]
| max | xml_schema_collection } ) ]
[ COLLATE collation_name ]
[ NULL | NOT NULL ]
| {ADD | DROP }
{ ROWGUIDCOL | PERSISTED | NOT FOR REPLICATION | SPARSE }
}
| [ WITH { CHECK | NOCHECK } ]
| ADD
{
column_definition
| computed_column_definition
| table_constraint
| column_set_definition
} [ ,...n ]
| DROP
{
[ CONSTRAINT ] constraint_name
[ WITH ( drop_clustered_constraint_option [ ,...n ] ) ]
| COLUMN column_name
} [ ,...n ]
| [ WITH { CHECK | NOCHECK } ] { CHECK | NOCHECK } CONSTRAINT
{ ALL | constraint_name [ ,...n ] }
| { ENABLE | DISABLE } TRIGGER
{ ALL | trigger_name [ ,...n ] }
| { ENABLE | DISABLE } CHANGE_TRACKING
[ WITH ( TRACK_COLUMNS_UPDATED = { ON | OFF } ) ]
| SWITCH [ PARTITION source_partition_number_expression ]
TO target_table
[ PARTITION target_partition_number_expression ]
| SET ( FILESTREAM_ON = { partition_scheme_name | filegroup |
"default" | "NULL" } )
| REBUILD
[ [PARTITION = ALL]
[ WITH ( rebuild_option [ ,...n ] ) ]
| [ PARTITION = partition_number
[ WITH ( single_partition_rebuild_option [ ,...n ] ) ]
]
]
| (table_option)
}
[ ; ]
column_set_definition ::=
column_set_name XML COLUMN_SET FOR ALL_SPARSE_COLUMNS
drop_clustered_constraint_option ::=
{
MAXDOP = max_degree_of_parallelism
| ONLINE = {ON | OFF }
| MOVE TO { partition_scheme_name ( column_name ) | filegroup
| "default" }
}
table_option ::=
{
SET ( LOCK_ESCALATION = { AUTO | TABLE | DISABLE } )
}
single_partition_rebuild__option ::=
{
SORT_IN_TEMPDB = { ON | OFF }
| MAXDOP = max_degree_of_parallelism
| DATA_COMPRESSION = { NONE | ROW | PAGE} }
}
sqlserver 下 修改表的某个字段默认值语法是怎么样的
一、代码如下:
alter table everygamelog drop constraint [DF_EveryGameLog_Memo]
ALTER TABLE everygamelog ADD
CONSTRAINT [DF_EveryGameLog_Memo] DEFAULT ( '正常') FOR [Memo]
二、sql server 字段设置约束
一)一.给字段添加默认值
语法:
alter table 表名 add constraint 约束名字 DEFAULT 默认值 for 字段名称
例:
alter table WD_Platform add constraint DF_WD_Platform_Platform_UID DEFAULT '' for Platform_UID
二)查找某字段默认约束名称
declare @constraint_name varchar(100)
select @constraint_name =obj.name from syscolumns as col
join sysobjects as obj on obj.id=col.cdefault
where col.id=object_id('WD_Platform') and col.name='Platform_UID'
select @constraint_name
说明: syscolumns用户数据库所定义的标字段都出在此.
sysobjects:用户数据库所定义的表,主键,外键,约束等都存放在这张系统表.
三)判断是否存在莫约束
if exists(select top 1 1 from sysobjects where name='DF_WD_Platform_Platform_UID') begin
select 约束存在
end
四)删除约束
ALTER TABLE WD_Platform DROP CONSTRAINT DF_WD_Platform_Platform_UID
备注约束不能直接修改,如果需要更改约束值,请先删除后,再创建.
先把所有‘替换成’‘’,再把‘’‘,’‘’替换成‘’,‘’
update 表名 set name =replace(name,‘'’,‘'''’)
update 表名 set name =replace(name,‘''','''’,‘'',''’)