pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <tfoot id='moKz5'></tfoot><legend id='moKz5'><style id='moKz5'><dir id='moKz5'><q id='moKz5'></q></dir></style></legend>

      • <bdo id='moKz5'></bdo><ul id='moKz5'></ul>

      1. <i id='moKz5'><tr id='moKz5'><dt id='moKz5'><q id='moKz5'><span id='moKz5'><b id='moKz5'><form id='moKz5'><ins id='moKz5'></ins><ul id='moKz5'></ul><sub id='moKz5'></sub></form><legend id='moKz5'></legend><bdo id='moKz5'><pre id='moKz5'><center id='moKz5'></center></pre></bdo></b><th id='moKz5'></th></span></q></dt></tr></i><div class="uiyosim" id='moKz5'><tfoot id='moKz5'></tfoot><dl id='moKz5'><fieldset id='moKz5'></fieldset></dl></div>
      2. <small id='moKz5'></small><noframes id='moKz5'>

      3. 如何在單個表中存儲多個選項?

        How to store multiple options in a single table?(如何在單個表中存儲多個選項?)
            <tbody id='vZwT2'></tbody>
            <legend id='vZwT2'><style id='vZwT2'><dir id='vZwT2'><q id='vZwT2'></q></dir></style></legend>
              <i id='vZwT2'><tr id='vZwT2'><dt id='vZwT2'><q id='vZwT2'><span id='vZwT2'><b id='vZwT2'><form id='vZwT2'><ins id='vZwT2'></ins><ul id='vZwT2'></ul><sub id='vZwT2'></sub></form><legend id='vZwT2'></legend><bdo id='vZwT2'><pre id='vZwT2'><center id='vZwT2'></center></pre></bdo></b><th id='vZwT2'></th></span></q></dt></tr></i><div class="si2u0sw" id='vZwT2'><tfoot id='vZwT2'></tfoot><dl id='vZwT2'><fieldset id='vZwT2'></fieldset></dl></div>
            • <small id='vZwT2'></small><noframes id='vZwT2'>

            • <tfoot id='vZwT2'></tfoot>

                  <bdo id='vZwT2'></bdo><ul id='vZwT2'></ul>
                  本文介紹了如何在單個表中存儲多個選項?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我想設(shè)計一個用于結(jié)果計算的應(yīng)用程序.

                  I want to design an application for result computation.

                  首先,我需要知道如何在 MySQL 數(shù)據(jù)庫中存儲記錄,以便學(xué)生可以擁有盡可能多的課程,例如學(xué)生A可以附上6個科目,而學(xué)生B可以附上12個科目.

                  First, I need to know how to store record in a MySQL database in such a way that students can have as many courses attached to them, e.g. student A can have 6 subjects attached to him, while student B can have 12 subject attached to him.

                  在這種情況下,我需要知道如何設(shè)計一個數(shù)據(jù)庫結(jié)構(gòu),允許一個字段以數(shù)組的形式存儲盡可能多的主題.

                  In this case, I need to know how I could possibly design a database structure that will allow a field to store as many subject as possible in form of an array.

                  我們將不勝感激任何建議或更好的處理方法.

                  Any suggestion or a better way to handle this will highly be appreciated.

                  推薦答案

                  請閱讀數(shù)據(jù)規(guī)范化、一般索引 概念和 外鍵 約束以保持?jǐn)?shù)據(jù)清潔和參照完整性.這會讓你繼續(xù)前進(jìn).

                  Please read up on Data Normalization, General Indexing concepts, and Foreign Key constraints to keep data clean with referential integrity. This will get you going.

                  在紙面上將數(shù)據(jù)存儲在數(shù)組中對您來說似乎很自然,但對于數(shù)據(jù)庫引擎而言,其性能大多不使用索引.此外,您會在第 2 天發(fā)現(xiàn)獲取和維護(hù)數(shù)據(jù)將是一場噩夢.

                  Storing data in arrays may seem natural to you on paper, but to the db engine the performance with mostly be without index use. Moreover, you will find on Day 2 that getting to and maintaining your data will be a nightmare.

                  以下內(nèi)容應(yīng)該可以讓您在修補(bǔ)時有一個良好的開端.也加入.

                  The following should get you going with a good start as you tinker. Joins too.

                  create table student
                  (   studentId int auto_increment primary key,
                      fullName varchar(100) not null
                      -- etc
                  );
                  
                  create table dept
                  (   deptId int auto_increment primary key,
                      deptName varchar(100) not null -- Economics
                      -- etc
                  );
                  
                  create table course
                  (   courseId int auto_increment primary key,
                      deptId int not null,
                      courseName varchar(100) not null,
                      -- etc
                      CONSTRAINT fk_crs_dept FOREIGN KEY (deptId) REFERENCES dept(deptId)
                  );
                  
                  create table SCJunction
                  (   -- Student/Course Junction table (a.k.a Student is taking the course)
                      -- also holds the attendance and grade
                      id int auto_increment primary key,
                      studentId int not null,
                      courseId int not null,
                      term int not null, -- term (I am using 100 in below examples for this term)
                      attendance int not null, -- whatever you want, 100=always there, 0=he must have been partying,
                      grade int not null, -- just an idea   
                      -- See (Note Composite Index) at bottom concerning next two lines.
                      unique key(studentId,courseId,term), -- no duplicates allowed for the combo (note student can re-take it next term)
                      key (courseId,studentId),
                      CONSTRAINT fk_sc_student FOREIGN KEY (studentId) REFERENCES student(studentId),
                      CONSTRAINT fk_sc_courses FOREIGN KEY (courseId) REFERENCES course(courseId)
                  );
                  

                  創(chuàng)建測試數(shù)據(jù)

                  insert student(fullName) values ('Henry Carthage'),('Kim Billings'),('Shy Guy'); -- id's 1,2,3
                  insert student(fullName) values ('Shy Guy');
                  
                  insert dept(deptName) values ('History'),('Math'),('English'); -- id's 1,2,3
                  
                  insert course(deptId,courseName) values (1,'Early Roman Empire'),(1,'Italian Nation States'); -- id's 1 and 2 (History dept)
                  insert course(deptId,courseName) values (2,'Calculus 1'),(2,'Linear Algebra A'); -- id's 3 and 4 (Math dept)
                  insert course(deptId,courseName) values (3,'World of Chaucer'); -- id 5 (English dept)
                  
                  -- show why FK constraints are important based on data at the moment
                  insert course(deptId,courseName) values (66,'Fly Fishing 101'); -- will generate error 1452. That dept 66 does not exist
                  -- That error is a good error to have. Better than faulty data
                  
                  -- Have Kim (studentId=2) enrolled in a few courses
                  insert SCJunction(studentId,courseId,term,attendance,grade) values (2,1,100,-1,-1); -- Early Roman Empire, term 100 (made up), unknown attendance/grade
                  insert SCJunction(studentId,courseId,term,attendance,grade) values (2,4,100,-1,-1); -- Linear Algebra A
                  insert SCJunction(studentId,courseId,term,attendance,grade) values (2,5,100,-1,-1); -- World of Chaucer
                  
                  -- Have Shy Guy (studentId=3) enrolled in one course only. He is shy
                  insert SCJunction(studentId,courseId,term,attendance,grade) values (3,5,100,-1,-1); -- Early Roman Empire, term 100 (made up), unknow attendance/grade
                  -- note if you run that line again, the Error 1062 Duplicate entry happens. Can't take same course more than once per term
                  

                  一些簡單的問題.

                  顯示全部,使用表格別名(縮寫)來減少打字次數(shù),提高可讀性(有時)

                  show all, uses table aliases (abbreviations) to make typing less, readability (sometimes) better

                  select c.courseId,c.courseName,d.deptId,d.deptName
                  from course c
                  join dept d
                  on c.deptId=d.deptId
                  order by d.deptName,c.courseName -- note the order
                  +----------+-----------------------+--------+----------+
                  | courseId | courseName            | deptId | deptName |
                  +----------+-----------------------+--------+----------+
                  |        5 | World of Chaucer      |      3 | English  |
                  |        1 | Early Roman Empire    |      1 | History  |
                  |        2 | Italian Nation States |      1 | History  |
                  |        3 | Calculus 1            |      2 | Math     |
                  |        4 | Linear Algebra A      |      2 | Math     |
                  +----------+-----------------------+--------+----------+
                  

                  本學(xué)期誰在學(xué)習(xí)喬叟世界的課程?

                  (知道 courseId=5)

                  Who is taking the World of Chaucer course this term?

                  (knowing the courseId=5)

                  以下受益于我們在 SCJunction 中的綜合索引之一.組合是在多個列上的索引.

                  The below benefits from one of our composite indexes in SCJunction. A composite is an index on more than one column.

                  select s.StudentId,s.FullName
                  from SCJunction j
                  join student s
                  on j.studentId=s.studentId
                  where j.courseId=5 and j.term=100
                  +-----------+--------------+
                  | StudentId | FullName     |
                  +-----------+--------------+
                  |         2 | Kim Billings |
                  |         3 | Shy Guy      |
                  +-----------+--------------+
                  

                  Kim Billings 在這個學(xué)期注冊了什么?

                  select s.StudentId,s.FullName,c.courseId,c.courseName
                  from SCJunction j
                  join student s
                  on j.studentId=s.studentId
                  join course c
                  on j.courseId=c.courseId
                  where s.studentId=2 and j.term=100
                  order by c.courseId DESC -- descending, just for the fun of it
                  +-----------+--------------+----------+--------------------+
                  | StudentId | FullName     | courseId | courseName         |
                  +-----------+--------------+----------+--------------------+
                  |         2 | Kim Billings |        5 | World of Chaucer   |
                  |         2 | Kim Billings |        4 | Linear Algebra A   |
                  |         2 | Kim Billings |        1 | Early Roman Empire |
                  +-----------+--------------+----------+--------------------+
                  

                  Kim 不知所措,所以放棄數(shù)學(xué)課

                  Kim is overwhelmed, so drop drop the math class

                  delete from SCJunction
                  where studentId=2 and courseId=4 and term=100
                  

                  運行上面的 select 語句,顯示 Kim 正在采取的措施:

                  run that above select statement showing what Kim is taking:

                  +-----------+--------------+----------+--------------------+
                  | StudentId | FullName     | courseId | courseName         |
                  +-----------+--------------+----------+--------------------+
                  |         2 | Kim Billings |        5 | World of Chaucer   |
                  |         2 | Kim Billings |        1 | Early Roman Empire |
                  +-----------+--------------+----------+--------------------+
                  

                  啊,更簡單的術(shù)語.不過爸爸不會高興的.

                  Ah, much easier term. Dad won't be happy though.

                  注意 SCJunction.term 之類的東西.關(guān)于這一點可以寫很多,我現(xiàn)在主要會跳過它,除了說它也應(yīng)該在某個 FK 中.您可能希望您的術(shù)語看起來更像 SPRING2015 而不是 int.

                  Note such things as SCJunction.term. Much can written about that, I will skip over it at the moment mostly, other than to say it should also be in an FK somewhere. You may want your term to look more like SPRING2015 and not an int.

                  就 id 而言.這就是我要做的方式.這是個人喜好.它需要知道 id #'s,查找它們.其他人可以選擇使用類似于 HIST101 而不是 17 的 courseId.它們的可讀性更高(但索引速度較慢(勉強(qiáng)).所以做最適合你的.

                  And as far as id's go. This is the way I would do it. It is personal preference. It would require knowing id #'s, looking them up. Others could choose to have a courseId something like HIST101 and not 17. Those are highly more readable (but slower in the index (barely). So do what is best for you.

                  復(fù)合索引(INDEX 表示 KEY,反之亦然)是一種組合多列以實現(xiàn)快速數(shù)據(jù)檢索的索引.SCJunction 表中兩個組合的順序被翻轉(zhuǎn),這樣,根據(jù)您的數(shù)據(jù)后的查詢范圍,數(shù)據(jù)庫引擎可以根據(jù)您要查找的最左邊的列來選擇使用哪個索引進(jìn)行最快的檢索.

                  A Composite Index (INDEX means KEY, and vice-versa) is one that combines multiple columns for fast data retrieval. The orders are flipped for the two composites in the SCJunction table so that, depending on the universe of queries that go after your data, the db engine can choose which index to use for fastest retrieval based on the left-most column you are going after.

                  至于唯一鍵,#1,它旁邊的注釋說明強(qiáng)制不重復(fù)(意味著垃圾數(shù)據(jù))是不言自明的.例如,學(xué)生 1 course 1 term 1 不能在該表中出現(xiàn)兩次.

                  As for the unique key, #1, the comment next to it stating enforcing no duplicates (meaning junk data) is rather self-explanatory. For instance, student 1 course 1 term 1 cannot exist twice in that table.

                  要理解的一個關(guān)鍵概念是索引中列名的最左排序概念.

                  A crucial concept to understand is the concept of left-most ordering of column names in an index.

                  對于在 studentId only 之后的查詢,首先列出 studentId 的鍵(最左邊) 使用.在courseId only 之后的查詢中,使用最左側(cè)具有courseId 的鍵.在同時跟蹤 studentId 和 courseId 的查詢中,數(shù)據(jù)庫引擎可以決定使用哪個組合鍵.

                  For queries that go after studentId only, then the key that has studentId listed first (left-most) is used. In queries that go after courseId only, then the key that has courseId left-most is used. In queries that go after both studentId and courseId, the db engine can decide which composite key to use.

                  當(dāng)我說追求"時,我的意思是在 on 子句where 子句 條件中.

                  When I say "go after", I mean in the on clause or where clause condition.

                  如果沒有這兩個組合鍵(其中的第 1 列和第 2 列翻轉(zhuǎn)),那么在查找的列未最左側(cè) 索引的查詢中,您將不會受益鍵使用,并遭受緩慢的表掃描以返回數(shù)據(jù).

                  Were one not to have those two composite keys (with the column 1 and 2 in them flipped), then in queries where the column sought is not left-most indexed, you would not benefit with key usage, and suffer a slow tablescan for data to return.

                  所以,這兩個索引結(jié)合了以下兩個概念

                  So, those two indexes combine the following 2 concepts

                  • 基于最左側(cè)或兩者(studentId 和 courseId 列)的快速數(shù)據(jù)檢索
                  • 根據(jù) studentId、courseId 和 term 值強(qiáng)制不重復(fù)該表中的數(shù)據(jù)

                  重要的要點是,聯(lián)結(jié)表有助于快速索引檢索,以及對數(shù)據(jù)與以逗號分隔的數(shù)據(jù)(數(shù)組思維)塞進(jìn)一列的理智管理,以及使用這樣的所有痛苦構(gòu)造.

                  The important takeaway is that Junction tables make for quick index retrieval, and sane management of data versus comma-delimited data (array mindset) crammed into a column, and all the misery of using such a construct.

                  這篇關(guān)于如何在單個表中存儲多個選項?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數(shù)根據(jù) N 個先前值來決定接下來的 N 個行)
                  reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達(dá)式的結(jié)果;條款?)
                  Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數(shù)的 ignore 選項是忽略整個事務(wù)還是只是有問題的行?) - IT屋-程序員軟件開發(fā)技
                  Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環(huán)數(shù)組)
                  pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調(diào)用 o23.load 時發(fā)生錯誤 沒有合適的驅(qū)動程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數(shù)據(jù)庫表作為 Spark 數(shù)據(jù)幀讀取?)

                  <small id='QZ2At'></small><noframes id='QZ2At'>

                • <i id='QZ2At'><tr id='QZ2At'><dt id='QZ2At'><q id='QZ2At'><span id='QZ2At'><b id='QZ2At'><form id='QZ2At'><ins id='QZ2At'></ins><ul id='QZ2At'></ul><sub id='QZ2At'></sub></form><legend id='QZ2At'></legend><bdo id='QZ2At'><pre id='QZ2At'><center id='QZ2At'></center></pre></bdo></b><th id='QZ2At'></th></span></q></dt></tr></i><div class="9j5xp7n" id='QZ2At'><tfoot id='QZ2At'></tfoot><dl id='QZ2At'><fieldset id='QZ2At'></fieldset></dl></div>
                  • <bdo id='QZ2At'></bdo><ul id='QZ2At'></ul>
                    <legend id='QZ2At'><style id='QZ2At'><dir id='QZ2At'><q id='QZ2At'></q></dir></style></legend>
                    • <tfoot id='QZ2At'></tfoot>

                              <tbody id='QZ2At'></tbody>
                            主站蜘蛛池模板: 特种电缆厂家-硅橡胶耐高温电缆-耐低温补偿导线-安徽万邦特种电缆有限公司 | 广州印刷厂_广州彩印厂-广州艺彩印务有限公司 | 合肥卓创建筑装饰,专业办公室装饰、商业空间装修与设计。 | 工控机-图像采集卡-PoE网卡-人工智能-工业主板-深圳朗锐智科 | 雷蒙磨,雷蒙磨粉机,雷蒙磨机 - 巩义市大峪沟高峰机械厂 | 整合营销推广|营销网络推广公司|石家庄网站优化推广公司|智营销 好物生环保网、环保论坛 - 环保人的学习交流平台 | 大连海岛旅游网>>大连旅游,大连海岛游,旅游景点攻略,海岛旅游官网 | 清水混凝土修复_混凝土色差修复剂_混凝土色差调整剂_清水混凝土色差修复_河南天工 | 土壤水分自动监测站-SM150便携式土壤水分仪-铭奥仪器 | 球磨机,节能球磨机价格,水泥球磨机厂家,粉煤灰球磨机-吉宏机械制造有限公司 | atcc网站,sigma试剂价格,肿瘤细胞现货,人结肠癌细胞株购买-南京科佰生物 | 翰香原枣子坊加盟费多少钱-正宗枣核糕配方培训利润高飘香 | 一体式钢筋扫描仪-楼板测厚仪-裂缝检测仪-泰仕特(北京) | 天津力值检测-天津管道检测-天津天诚工程检测技术有限公司 | 排烟防火阀-消防排烟风机-正压送风口-厂家-价格-哪家好-德州鑫港旺通风设备有限公司 | 制样机-密封锤式破碎机-粉碎机-智能马弗炉-南昌科鑫制样 | 交流伺服电机|直流伺服|伺服驱动器|伺服电机-深圳市华科星电气有限公司 | 截齿|煤截齿|采煤机截齿|掘进机截齿|旋挖截齿-山东卓力截齿厂家报价 | 工控机-工业平板电脑-研华工控机-研越无风扇嵌入式box工控机 | 变色龙云 - 打包app_原生app_在线制作平台_短链接_ip查询 | 河南膏药贴牌-膏药代加工-膏药oem厂家-洛阳今世康医药科技有限公司 | 南京交通事故律师-专打交通事故的南京律师| pos机办理,智能/扫码/二维码/微信支付宝pos机-北京万汇通宝商贸有限公司 | 硬质合金模具_硬质合金非标定制_硬面加工「生产厂家」-西迪技术股份有限公司 | 气动|电动调节阀|球阀|蝶阀-自力式调节阀-上海渠工阀门管道工程有限公司 | 周口风机|周风风机|河南省周口通用风机厂 | 挤塑板-XPS挤塑板-挤塑板设备厂家[襄阳欧格] | 在线浊度仪_悬浮物污泥浓度计_超声波泥位计_污泥界面仪_泥水界面仪-无锡蓝拓仪表科技有限公司 | 一航网络-软件测评官网 | 传递窗_超净|洁净工作台_高效过滤器-传递窗厂家广州梓净公司 | 翅片管换热器「型号全」_厂家-淄博鑫科环保 | 能量回馈_制动单元_电梯节能_能耗制动_深圳市合兴加能科技有限公司 | 专业的新乡振动筛厂家-振动筛品质保障-环保振动筛价格—新乡市德科筛分机械有限公司 | 济南ISO9000认证咨询代理公司,ISO9001认证,CMA实验室认证,ISO/TS16949认证,服务体系认证,资产管理体系认证,SC食品生产许可证- 济南创远企业管理咨询有限公司 郑州电线电缆厂家-防火|低压|低烟无卤电缆-河南明星电缆 | 知网论文检测系统入口_论文查重免费查重_中国知网论文查询_学术不端检测系统 | 新材料分散-高速均质搅拌机-超声波分散混合-上海化烁智能设备有限公司 | 防勒索软件_数据防泄密_Trellix(原McAfee)核心代理商_Trellix(原Fireeye)售后-广州文智信息科技有限公司 | 质检报告_CE认证_FCC认证_SRRC认证_PSE认证_第三方检测机构-深圳市环测威检测技术有限公司 | 西安微信朋友圈广告投放_微信朋友圈推广_西安度娘网络科技有限公司 | 工业硝酸钠,硝酸钠厂家-淄博「文海工贸」 | 叉车电池-叉车电瓶-叉车蓄电池-铅酸蓄电池-电动叉车蓄电池生产厂家 |