在 sql 中存储文本和数字
store both text and number in sql
如何在 sql 的同一字段中存储文本和整数?
想要这样存储:例如:Jh_123
我正在使用 phpmyadmin。
并且还想用作 "UNIQUE" 字段?
谢谢
您可以使用 NVARCHAR 数据类型来保留文本和数字。
Character data types that are either fixed-length, nchar, or
variable-length, nvarchar, Unicode data and use the UNICODE UCS-2
character set.
如您的评论所示:
CREATE TABLE Test
(
Id INT,
Name NVARCHAR(50) UNIQUE
)
INSERT INTO Test VALUES (1, 'Jh_123')
SELECT * FROM Test
结果将是:1 Jh_123
使用 nvarchar(max) 然后通过放置 where 条件检索数据
当你只想获取 int 值时,你可以使用
where column>0
如何在 sql 的同一字段中存储文本和整数?
想要这样存储:例如:Jh_123
我正在使用 phpmyadmin。
并且还想用作 "UNIQUE" 字段?
谢谢
您可以使用 NVARCHAR 数据类型来保留文本和数字。
Character data types that are either fixed-length, nchar, or variable-length, nvarchar, Unicode data and use the UNICODE UCS-2 character set.
如您的评论所示:
CREATE TABLE Test
(
Id INT,
Name NVARCHAR(50) UNIQUE
)
INSERT INTO Test VALUES (1, 'Jh_123')
SELECT * FROM Test
结果将是:1 Jh_123
使用 nvarchar(max) 然后通过放置 where 条件检索数据
当你只想获取 int 值时,你可以使用
where column>0