MS sql 数据库中 guid 类型 能否默认添加空值.
不是 Guid.NewGuid();
能的话,要怎么添加, 请高人指点...
5 个解决方案
#1
create table tb(id int, col uniqueidentifier default null)
insert tb(id)
select 1
select * from tb
drop table tb
#2
正解.
#3
..
#4
CREATE TABLE MyUniqueTable
(UniqueColumn UNIQUEIDENTIFIER DEFAULT null,
Characters VARCHAR(10) )
GO
INSERT INTO MyUniqueTable(Characters) VALUES ('abc')
INSERT INTO MyUniqueTable VALUES (NEWID(), 'def')
GO
select * from MyUniqueTable
UniqueColumn Characters
------------------------------------ ----------
NULL abc
0B3C117B-7769-4F62-8CDD-3A892A463F24 def
(2 行受影响)
#5
帮顶
#1
create table tb(id int, col uniqueidentifier default null)
insert tb(id)
select 1
select * from tb
drop table tb
#2
正解.
#3
..
#4
CREATE TABLE MyUniqueTable
(UniqueColumn UNIQUEIDENTIFIER DEFAULT null,
Characters VARCHAR(10) )
GO
INSERT INTO MyUniqueTable(Characters) VALUES ('abc')
INSERT INTO MyUniqueTable VALUES (NEWID(), 'def')
GO
select * from MyUniqueTable
UniqueColumn Characters
------------------------------------ ----------
NULL abc
0B3C117B-7769-4F62-8CDD-3A892A463F24 def
(2 行受影响)
#5
帮顶