插入几行的一个表或单独插入行许多表格? [英] Insert many rows to one table OR insert rows separately to many table?

查看:155
本文介绍了插入几行的一个表或单独插入行许多表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数据库表(SQL CE)。 A 教师表和A 表。这两个表有一到多,其中一个老师有许多类的关系(即有一个外键的 teacher_id )。教师(行)数插入(或产生)通过运行时的C#代码,从而班



以下哪项是INSERT速度更快,选择?




  1. 每次新老师插入,一类新的表被创建(如Class_teacher001)来存储的老师有任何类。在这种情况下,每个班表不必是不需要那么大和外键,因为表的名称将确定本身。但会有一位老师桌子和许多Class_xxx表



  2. 只有一个老师表和一个Class表。每个类行有在老师表的外键指向。只有一个级表,但它会变得非常长。我担心搜索和阅读时便会慢


解决方案

无论哪个速度更快,(2)是要走的路....简单地创建索引,以支持搜索。这就是几乎所有的关系型数据库被使用。



维护选项的噩梦(1)让我不寒而栗


I have two DataBase Table (SQL CE). A Teacher table and a A Class table. The two tables have One-to-Many relationship where one teacher has many classes (i.e. Class has a foreign key teacher_id). Number of teachers (rows) is inserted (or generated) through C# code in run time, so as classes

Which of the following is faster in INSERT and SELECT?

  1. Each time a new teacher is INSERTed, a new Class Table is created (e.g. Class_teacher001) to store whichever classes the teacher has. In this case, each Class Table doesn't have to be so large and foreign key is not needed because table name would identify itself. But there will be one Teacher table and many Class_xxx Tables

  2. Only one Teacher table and one Class table. Each class row has a foreign key pointing at the Teacher table. Only one Class table, but it will get very long. I worry searching and reading wil be slow

解决方案

Regardless of which is faster, (2) is the way to go....simply create indexes to support your searches. This is how almost all relational databases are used.

The nightmare of maintaining option (1) makes me shudder

这篇关于插入几行的一个表或单独插入行许多表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆