我正在为我的游戏制作一个数据库,我需要存储很多 c 风格的结构体.
I'm making a database for my game and I need to store a lot of c style structs.
struct stats{
int strength, stamina, agility, intelligence, etc..;
}
我一直在研究如何在 t-sql 中创建用户定义的数据类型,MSDN 特别指出用户定义的数据类型不能用作列类型:
I've been looking at how to create user defined data types in t-sql and MSDN specifically says that user defined data types CANNOT be used as a column type:
用户定义的表类型不能用作表中的列或结构化用户定义类型中的字段.
有没有解决方法,或者在那里创建基于结构的系统的其他方法?我还需要一个技能结构,我有大约 120 多个技能需要存储在我的播放器表下.我想要的表看起来像这样:
Is there not a work around, or some other way to create a struct based system in there? I also need a struct for skills and i have around 120+ skills that need to be stored under my player table. My desired table would look something like this:
CREATE TABLE [dbo].[Player](
player_name nvarchar (20),
gold int,
player_stats stats, // array of 4 ints
player_skills skills, // array of 120+ tinyints
player_location location, // array of 3 floats (x,y,z)
player_customization customization, // array of 20+ tinyints
player_equipment equipment, // array of 8 ints
etc....)
有没有一种简单的方法可以做到这一点,还是我只需要将所有这些添加为单独的列类型?感谢您的帮助.
Is there a simple way of doing this or do i just need to add all those as individual column types? Thanks for the help.
这是你的桌子:
CREATE TABLE [dbo].[Players](
player_name nvarchar (20),
gold int,
player_stats stats, // array of 4 ints
player_skills skills, // array of 120+ tinyints
player_location location, // array of 3 floats (x,y,z)
player_customization customization, // array of 20+ tinyints
player_equipment equipment, // array of 8 ints
etc....
)
这表明您应该有几个其他的表和列:
This suggests that you should have several other tables and columns:
Player_Skills
和 Skills
:每个玩家和每个技能一行,可能还有一个技能级别列.Location
:每个位置一行,包含有关该位置的信息.LocationId
将在 Players
表中.Player_Equipment
和 Equipment
:每个玩家和每个装备一行.Player_Skills
and Skills
: One row per player and per skill, with perhaps a skill level column as well.Location
: One row for each location, with information about the location. LocationId
would be in the Players
table.Player_Equipment
and Equipment
: One row per player and per equipment.我不知道player_stats
和player_customization
是什么.也许它们只是适合 Players
的列;也许他们应该是他们自己的桌子.
I don't know what player_stats
and player_customization
are. Perhaps they are just appropriate columns for Players
; perhaps they should be their own tables.
您从结构"等编程结构的角度考虑关系数据库是不合适的.
You're thinking of a relational database in terms of programming constructs such as "structures" is not appropriate.
这篇关于将结构类型创建为 T-SQL 的列值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!