SQL 存储有关列的数据
我正在为我正在编写的需要本地数据库的程序学习 SQL Server Compact。我有多个表,每个表都有不同的列,我想将每个列标记为某种类型(不是数据类型,只是整数标记),以便让程序知道如何处理它。我对SQL一窍不通。如何做到这一点?
I'm learning SQL Server Compact for a program I'm writing that requries a local database. I have multiple tables, each with different columns and I'd like to mark each column as being a certain type (not a data type, just an integer tag) to let the program know what to do with it. I'm clueless about SQL. How does one do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将使用扩展属性来存储该元数据。例如:
将“columntag”替换为您想要引用“整数标记”的任何内容,将“mytable”替换为表的名称,将“id”替换为相关列的名称,“123”是您的您存储以供查找的整数值。第一个语句添加扩展属性,第二个语句是您如何以编程方式检索它。
I would use extended properties to store that meta data. For example:
Replace 'columntag' with whatever you want to refer to your "integer tag" as, 'mytable' with the name of your table, 'id' with the name of the column in question, and the '123' is your integer value you are storing for lookup. The first statement adds the extended property, and the second is how you would/could retrieve it programatically.
我建议您创建用户定义类型并让您的代码在您定义的类型上工作,即。
现在,您的程序将看到类型电话并决定要做什么
I would suggest you create User-Defined types and let your code work on the type you defined, ie.
Now, your program would see the type Telephone and decide what to do
SQL Server 将这些信息存储在系统表中。 Sysobjects 保存表信息。 Sycolumns 保存列信息。您可以在 systypes 中找到数据类型。
Sysobjects 和 syscolumns 在 id 列上连接。我不记得鞠躬加入 systypes 但快速谷歌搜索会给你答案。
SQL Server stores this information in system tables. Sysobjects hold table info. Syscolumns holds column info. You can find data typy in systypes.
Sysobjects and syscolumns join on the id column. I don't remember bow to join to systypes but a quick google search will give you the answer.