现在我想要有一个事件表,应该保持与我的数据库相关的所有事件。但是,这个表格的一个字段应该是与该事件必须做的记录相关的字段 ObjectID 。但是这个记录可能在不同的表格上。例如:
- 事件1 ----表客户端记录25
- 事件2 - ---记录30表发票
- 事件3 ----记录40表文章 ...
问题是这个字段 ObjectID 应该是一个灵活的外键,因为可能与不同的表相关。
有什么办法可以解决这个问题吗?
谢谢!
解决方案您可以创建一个INDEXED VIEW - 定义它,但是您希望将objectIDs +任何其他相关字段(如您所述)从记录25客户表,记录记录30的发票表,等等。
您可以使用存储过程执行相同的操作。
根据您打算如何使用数据 - 如果您只是将其拉入vb数据表中,则这两个选项都可以正常运行。
这样的方法就是您不必在数据库中创建或维护任何新表。I have a sql server database. I'm developing a vb application.
Now I'm thinking to have an "Event" table that should keep all the events related with my database. But one of the fields of this table should be a field ObjectID that is related with the record that this event has to do. But this record may be on different tables. For example :
- Event 1 ---- Record 25 on table Clients
- Event 2 ---- Record 30 Table Invoices
- Event 3 ---- Record 40 Table Articles ...
The problem is that this field ObjectID should be a Foreign key in a flexible way , because may be related with different tables.
Is there any way I can resolve this case ?
Thank you !
解决方案You could create an 'INDEXED VIEW' -- define it however you like to pull the objectIDs + any other relevant fields, as you've described, from record 25 of the clients table, record record 30 of the invoices table, and so on.
You could do the same thing with a stored procedure.
Depending on how you intend to consume the data -- if you're just pulling it into a vb datatable, either of these options should work fine.
A benefit to an approach like this is that you don't have to create or maintain any new tables in your database.
更多推荐
灵活的外键
发布评论