SQL Server alter column table and make default value to empty string

erhoui1w  于 2023-02-28  发布在  其他
关注(0)|答案(4)|浏览(137)

Good day, just want to ask, is it possible to alter a column table and make the default value to empty string.

I tried using this query,

Alter Table Employee Alter Column sJobTitle Varchar(200) DEFAULT ''

Unfortunately, it doesn't work..

Please let me know, if 'm doing it correct..

Thanks,

Link

zlhcx6iw

zlhcx6iw1#

You need to add a constraint.

Referring to SQL SERVER – Create Default Constraint Over Table Column

ALTER TABLE Employee 
  ADD CONSTRAINT DF_Employee _JobTitle
  DEFAULT '' FOR sJobTitle
q43xntqr

q43xntqr2#

try this query. this query does not change current datas to default.

ALTER TABLE Employee
ADD DEFAULT ('') FOR sJobTitle

maybe it work.

cunj1qz1

cunj1qz13#

ALTER TABLE Employee 
ADD sJobTitle varchar(200) NOT NULL DEFAULT ''

simplest answer.

b09cbbtk

b09cbbtk4#

You can try this, single and multiple column

Single column:

ALTER TABLE `DBname`.`table_name` 
 MODIFY COLUMN `foo_name` VARCHAR(255) NOT NULL DEFAULT '';

multiple column:

ALTER TABLE `DBname`.`table_name`
 MODIFY COLUMN `foo_name` VARCHAR(255) NOT NULL DEFAULT '',
 MODIFY COLUMN `foo_roll` VARCHAR(65) NOT NULL DEFAULT '';

相关问题