SQL中增加列时怎么设置默认值?删除列时restrict怎么报错啊?

SQL中增加列时怎么设置默认值?删除列时restrict怎么报错啊?,第1张

第一个问题:为表新增的默认值只有在后续增加数据的时候才会设置默认值,原来的数据是不会变化的。

第二个问题:删除列语法 alter table frame_user drop column sex3

alter

table

表名

drop

constraint

约束名字

说明:删除表的字段的原有约束

alter

table

表名

add

constraint

约束名字

default

默认值

for

字段名称

说明:添加一个表的字段的约束并指定默认值go例:alter

table

t_ping

drop

constraint

df_t_ping_p_c

alter

table

t_ping

add

constraint

df_t_ping_p_c

default

((2))

for

p_cgoalter

table

with

check

t_ping

add

constraint

df_t_ping_p_c

default

((2))

for

p_c

alter

table

with

nocheck

t_ping

add

constraint

df_t_ping_p_c

default

((2))

for

p_c

两者的区别是if

you

do

not

want

to

verify

new

check

or

foreign

key

constraints

against

existing

data,

use

with

nocheck.

this

is

not

recommended

except

in

rare

cases.

the

new

constraint

will

be

evaluated

in

all

future

updates.

对于要建立约束的两个表,如果其中的一个已有数据,把在创建时检查现有数据选项设置为是将告诉sql

server:当开始具体创建约束时,要对表中现有的数据进行检查。如果现有数据符合约束的定义,则约束被成功加入到表中源码天空


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/8028547.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-12
下一篇2023-04-12

发表评论

登录后才能评论

评论列表(0条)

    保存