22,209
社区成员
发帖
与我相关
我的任务
分享
('')
CREATE TABLE #th
(
id INT IDENTITY,
NAME VARCHAR(10) NOT NULL DEFAULT ''
)
select * FROM #th t
INSERT INTO #th SELECT ''
CREATE TABLE #tk
(
ID INT IDENTITY,
NAME VARCHAR(10)
)
select * FROM #tk t
INSERT INTO #tk SELECT null
use test
go
if object_id('test.dbo.tb') is not null drop table tb
-- 创建数据表
create table tb
(
Type char(3),
Dtext char(7)
)
go
--插入测试数据
insert into tb select 'A1','计算机'
go
--代码实现
select * from tb
/*测试结果
Type Dtext
---------------------
A1 计算机
(1 行受影响)
*/
insert into tb(Type) values('A2')
select * from tb
/*测试结果
Type Dtext
---------------------
A1 计算机
A2 NULL
(2 行受影响)
*/
alter table tb add default('') for Dtext with values
insert into tb(Type) values('A3')
insert into tb(Type,Dtext) values('A4','英语')
select * from tb
/*测试结果
Type Dtext
---------------------
A1 计算机
A2 NULL
A3
A4 英语
(4 行受影响)
*/