视图的列包含看起来像 UUID 但列类型为 int 的数据。为什么?
View's column contains data which looks like UUID but the column type is int. Why?
我可以访问 SQL Server 2016 数据库的视图。
名为 'id_key' 的列包含这样的数据:
id_key
D93F37FC-3C2A-EB11-B813-00505690E502
B03D37FC-3C2A-EB11-B813-00505690E502
AC644CFC-3C2A-EB11-B813-00505690E502
我检查了列的类型:它是 int
真的,结果:
SELECT DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'yourTableName' AND
COLUMN_NAME = 'yourColumnName'
returns 只是 int
.
我在 SQL Server 2016 文档中没有找到任何解释。
我错过了什么吗?
int
如何输入看起来像 strings/uuids 的存储数据?
如果视图不是使用 WITH SCHEMABINDING
选项创建的,那么它引用的基础表可以自由更改。
可能有问题的列在创建视图时最初使用 int
数据类型,但后来更改为 uniqueidentifier
,例如:
drop view if exists dbo.yourViewName;
drop table if exists dbo.yourTableName;
go
create table dbo.yourTableName (
ignore int,
yourColumnName int
);
go
create view dbo.yourViewName --with schemabinding
as
select yourColumnName as id_key
from dbo.yourTableName
go
alter table dbo.yourTableName
drop column yourColumnName
go
alter table dbo.yourTableName
add yourColumnName uniqueidentifier
go
insert dbo.yourTableName (yourColumnName) values
('D93F37FC-3C2A-EB11-B813-00505690E502'),
('B03D37FC-3C2A-EB11-B813-00505690E502'),
('AC644CFC-3C2A-EB11-B813-00505690E502')
go
select * from dbo.yourViewName
go
select data_type
from information_schema.columns
where table_name = 'yourViewName'
and column_name = 'id_key'
产生:
id_key
------------------------------------
D93F37FC-3C2A-EB11-B813-00505690E502
B03D37FC-3C2A-EB11-B813-00505690E502
AC644CFC-3C2A-EB11-B813-00505690E502
data_type
----------
int
有关详细信息,请参阅 CREATE VIEW (Transact-SQL) 文档。
我可以访问 SQL Server 2016 数据库的视图。
名为 'id_key' 的列包含这样的数据:
id_key
D93F37FC-3C2A-EB11-B813-00505690E502
B03D37FC-3C2A-EB11-B813-00505690E502
AC644CFC-3C2A-EB11-B813-00505690E502
我检查了列的类型:它是 int
真的,结果:
SELECT DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'yourTableName' AND
COLUMN_NAME = 'yourColumnName'
returns 只是 int
.
我在 SQL Server 2016 文档中没有找到任何解释。
我错过了什么吗?
int
如何输入看起来像 strings/uuids 的存储数据?
如果视图不是使用 WITH SCHEMABINDING
选项创建的,那么它引用的基础表可以自由更改。
可能有问题的列在创建视图时最初使用 int
数据类型,但后来更改为 uniqueidentifier
,例如:
drop view if exists dbo.yourViewName;
drop table if exists dbo.yourTableName;
go
create table dbo.yourTableName (
ignore int,
yourColumnName int
);
go
create view dbo.yourViewName --with schemabinding
as
select yourColumnName as id_key
from dbo.yourTableName
go
alter table dbo.yourTableName
drop column yourColumnName
go
alter table dbo.yourTableName
add yourColumnName uniqueidentifier
go
insert dbo.yourTableName (yourColumnName) values
('D93F37FC-3C2A-EB11-B813-00505690E502'),
('B03D37FC-3C2A-EB11-B813-00505690E502'),
('AC644CFC-3C2A-EB11-B813-00505690E502')
go
select * from dbo.yourViewName
go
select data_type
from information_schema.columns
where table_name = 'yourViewName'
and column_name = 'id_key'
产生:
id_key
------------------------------------
D93F37FC-3C2A-EB11-B813-00505690E502
B03D37FC-3C2A-EB11-B813-00505690E502
AC644CFC-3C2A-EB11-B813-00505690E502
data_type
----------
int
有关详细信息,请参阅 CREATE VIEW (Transact-SQL) 文档。