alter table tablename alter column [datatype]
尖扎網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),尖扎網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為尖扎成百上千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢(qián),請(qǐng)找那個(gè)售后服務(wù)好的尖扎做網(wǎng)站的公司定做!
比如我的表A中有個(gè)列叫 patientNo目前是int,我希望更改為varchar(50),不為空
alter table A alter patientNo varchar(50) not null
用update
set就可以了
update
表名
set
要修改的屬性和值
如果你要修改具體的某列的某個(gè)屬性可以在后面查出來(lái)用where
比如你說(shuō)的a表中
id為1的數(shù)據(jù)中
b列下的值修改為2
update
a
set
b=2
where
id=1
使用腳本修改吧,界面也可以
腳本如下:
Alter table [表名] Alter column [列名] [列類(lèi)型] [NOT NULL或者 NULL]
alter table 腳本很豐富,可以查看MS SQL的幫助,新手做baidu任務(wù),給個(gè)滿意吧
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 下 修改表的某個(gè)字段默認(rèn)值語(yǔ)法是怎么樣的
一、代碼如下:
alter table everygamelog drop constraint [DF_EveryGameLog_Memo]
ALTER TABLE everygamelog ADD
CONSTRAINT [DF_EveryGameLog_Memo] DEFAULT ( '正常') FOR [Memo]
二、sql server 字段設(shè)置約束
一)一.給字段添加默認(rèn)值
語(yǔ)法:
alter table 表名 add constraint 約束名字 DEFAULT 默認(rèn)值 for 字段名稱(chēng)
例:
alter table WD_Platform add constraint DF_WD_Platform_Platform_UID DEFAULT '' for Platform_UID
二)查找某字段默認(rèn)約束名稱(chēng)
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
說(shuō)明: syscolumns用戶(hù)數(shù)據(jù)庫(kù)所定義的標(biāo)字段都出在此.
sysobjects:用戶(hù)數(shù)據(jù)庫(kù)所定義的表,主鍵,外鍵,約束等都存放在這張系統(tǒng)表.
三)判斷是否存在莫約束
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
備注約束不能直接修改,如果需要更改約束值,請(qǐng)先刪除后,再創(chuàng)建.
先把所有‘替換成’‘’,再把‘’‘,’‘’替換成‘’,‘’
update 表名 set name =replace(name,‘'’,‘'''’)
update 表名 set name =replace(name,‘''','''’,‘'',''’)