Database Design and ER Diagram

Database design નક્કી કરે છે કે project data કેવી રીતે store કરશે. Entity-relationship diagramથી entities, attributes અને relationships ઓળખીને data organised, consistent અને unnecessary duplication વગર રાખી શકાય છે.

10 min read · 6 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

Data ક્યાં રહે તે design કરવું

લગભગ દરેક projectમાં data હોય છે: students, events, orders અને records. આ dataને કેવી રીતે organise કરો છો તેના પર projectની consistency અને query કરવાની સરળતા ઘણી આધારિત છે. Design સાચું હોય તો system maintain કરવું સરળ રહે છે; ખોટું હોય તો duplication અને inconsistencyની સમસ્યાઓ વારંવાર આવે છે.

Database design આ structureનું planning છે. તેનો classic tool entity-relationship (ER) diagram છે, જે તમે DBMSમાં શીખ્યા છો. આ lessonમાં projectની requirements પરથી entities, તેમના attributes અને તેમની વચ્ચેના relationships ઓળખીને tables બનાવતાં પહેલાં clean data blueprint તૈયાર કરશો.

Theory

Entities, attributes અને relationships

ER diagram dataને ત્રણ મુખ્ય ingredients વડે model કરે છે.

Entities એટલે જે વસ્તુઓ વિશે તમે data store કરો છો: systemના nouns, જેમ કે Student, Event અને Registration. દરેક entity સામાન્ય રીતે એક table બને છે.

Attributes entityની properties છે: Student પાસે name, email અને id; Event પાસે title, date અને venue. દરેક entityને unique identifier તરીકે primary key આપવી જોઈએ.

Relationships entitiesને connect કરે છે: Student Event માટે register કરે છે. Relationshipsમાં cardinality હોય છે: one-to-one, one-to-many અથવા many-to-many. તે બતાવે છે કે એક entity કેટલા બીજા entities સાથે જોડાઈ શકે છે. Student ઘણા events માટે register કરી શકે છે અને એક eventની ઘણી registrations હોઈ શકે છે.

Requirementsમાંથી આ elements ઓળખો અને તમારું data structure map થઈ જશે.

Formula

Duplication ટાળવા normalise કરો

Good database designનો મુખ્ય goal redundancy ઘટાડવો છે, એટલે same dataને અનેક જગ્યાએ store ન કરવું. DBMSમાં શીખેલું normalisation dataને એવી રીતે organise કરે છે કે દરેક fact એક જ જગ્યાએ રહે.

આ જરૂરી કેમ છે? જો studentનો email ઘણી rowsમાં duplicate હોય અને email બદલાય, તો દરેક copy update કરવી પડશે. એક copy રહી જાય તો data inconsistent બની જશે: હવે સાચું email કયું છે? દરેક fact એક વાર store કરીને keys અને relationships વડે link કરશો તો data consistent અને maintainable રહે છે. Clean normalised design code લખતાં પહેલાં જ bugsની આખી category અટકાવે છે.

Quiz

Projectના ER diagramમાં 'entity' શું represent કરે છે?

  1. User interfaceની colour scheme
  2. જે વસ્તુ વિશે data store કરો છો, જેમ કે Student, Event અથવા Registration, જેમાં attributes અને primary key હોય છે
  3. Databaseની speed
  4. Codeમાંનું એક function
Show the answer

જે વસ્તુ વિશે data store કરો છો, જેમ કે Student, Event અથવા Registration, જેમાં attributes અને primary key હોય છે

ER diagramમાં entity એવી વસ્તુ represent કરે છે જેના વિશે data store થાય છે, જેમ કે Student, Event અથવા Registration. તેમાં attributes હોય છે, જેમ કે name અને email, અને unique identifier તરીકે primary key હોય છે. Option A UI/UX designનો વિષય છે, data entityનો નહીં. Option C performance concern છે, entityની definition નહીં. Option D code logic છે, data entity નહીં. Entities systemના 'things' અથવા nouns છે; attributes તેમને describe કરે છે અને relationships તેમને connect કરે છે.

Think first

Tables બનાવતાં પહેલાં ER diagramથી database design કેમ કરવું?

તમે જરૂર મુજબ tables બનાવતા જઈ શકો છો. તો પહેલાં ER diagramમાં data model શા માટે કરવું? પછી tap.

Show the answer

કારણ કે database આખી applicationનો FOUNDATION છે અને તેની structureમાં થયેલી ભૂલો પછીથી સુધારવી ખૂબ costly બને છે. ER diagramથી tables અને code લખતા પહેલાં design carefully check કરી શકાય છે.

Applicationના લગભગ દરેક ભાગને database read અથવા write કરે છે. Tables બનાવ્યા પછી forms, queries અને features તેમની structure પર depend કરવા લાગે છે. જો ad hoc coding દરમિયાન પછી ખબર પડે કે કોઈ entity missing છે, relationships tangled છે અથવા data અનેક જગ્યાએ duplicate છે, તો database સાથે તેને વાપરતો બધો code પણ ફરીથી બદલવો પડે છે. આ ખાસ કરીને projectના અંતમાં મોટું અને error-prone કામ બને છે.

ER diagramમાં design UP FRONT વિચારવાથી entities અને relationships એકસાથે દેખાય છે. Missing અથવા wrong connections, primary keys અને duplication પહેલાં જ ઓળખી શકાય છે. Normalisation કરીને consistent structure તૈયાર કરી શકાય છે. Teamના બધા members માટે આ shared picture બને છે અને report તથા presentation માટે documentation પણ આપે છે.

ER diagram dataનું blueprint છે. Building foundation plan વગર ન બનાવો, તેમ database પણ design વગર ન બનાવો. પહેલાં data model કરો, foundation સાચી કરો અને પછી તેના પર project build કરો.

Summary

Key takeaways

  • Database design project data કેવી રીતે store થશે તેનું planning છે; ER diagram તેનું મુખ્ય tool છે.
  • Entities એટલે જે વસ્તુઓ વિશે data store થાય છે, જેમ કે Student, Event અને Registration; દરેકને primary key આપો.
  • Attributes entityની properties છે, જેમ કે Studentનું name, email અને id.
  • Relationships entitiesને જોડે છે, જેમ કે Student Event માટે register કરે છે; cardinality one-to-one, one-to-many અથવા many-to-many હોઈ શકે છે.
  • Redundancy ઘટાડવા design normalise કરો અને દરેક fact એક જ જગ્યાએ store કરો.
  • Tables બનાવતાં પહેલાં requirements પરથી ER model design કરો, કારણ કે database આખી applicationનો foundation છે.
  • Memory hook: entities એટલે things, attributes એટલે properties અને relationships એટલે links; ER diagram બનાવો, normalise કરો, પછી build કરો.

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Project Design and Architecture

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

Database Design and ER Diagram · Project (Major-16) · Gri-Learn