問題描述
我正在為我的游戲制作一個數據庫,我需要存儲很多 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
andSkills
: 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 thePlayers
table.Player_Equipment
andEquipment
: 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模板網!