סידרת SQL בסיסי - פוסט 2 - הטבלה השניה

11/08/2024

המעבר לטבלה כבר עזר לנו להבין טוב יותר את המידע שלנו. עכשיו בואו נראה אם ומתי כדאי לנו לארגן את המידע במספר טבלאות ואיך עושים את זה.

1. קצת יותר פרטים

אני ממשיך עם דוגמת הטיול לפריז שבנינו בשיעור הקודם ומזכיר שזאת היתה רשימת המקומות בהם רצינו לבקר:

| Day | Hour | Attraction / Restaurant Name | Attraction / Restaurant Address | Visit Duration | Rank | Need to Reserve in Advance (Yes/No) | |------|------------|-----------------------------|------------------------------------------|----------------|------|--------------------------------------| | 1 | 12:00 PM | Hôtel Le Bristol Paris | 112 Rue du Faubourg Saint-Honoré, 75008 | 1 hour | 5 | Yes | | 1 | 12:00 PM | Novotel Paris Les Halles | 8 Place Marguerite de Navarre, 75001 | 1 hour | 5 | Yes | | 1 | 2:00 PM | Louvre Museum | Rue de Rivoli, 75001 | 3 hours | 1 | Yes | | 1 | 6:00 PM | Le Café Marly | 93 Rue de Rivoli, 75001 | 1.5 hours | 3 | Yes | | 2 | 9:00 AM | Eiffel Tower | Champ de Mars, 5 Av. Anatole France, 75007 | 2 hours | 1 | Yes | | 2 | 12:00 PM | Café de l'Homme | 17 Place du Trocadéro, 75116 | 1.5 hours | 4 | Yes | | 2 | 2:30 PM | Seine River Cruise | Various locations | 1.5 hours | 2 | Yes | | 2 | 7:00 PM | Le Relais de l'Entrecôte | 15 Rue Marbeuf, 75008 | 1.5 hours | 4 | No | | 3 | All Day | Disneyland Paris | Boulevard de Parc, 77700 Coupvray | 8 hours | 1 | Yes | | 3 | 7:00 PM | Agrabah Café | Disneyland Park | 1 hour | 3 | Yes | | 4 | 10:00 AM | Musée d'Orsay | 1 Rue de la Légion d'Honneur, 75007 | 2.5 hours | 2 | Yes | | 4 | 12:30 PM | Le Petit Cler | 29 Rue Cler, 75007 | 1.5 hours | 4 | No | | 4 | 2:30 PM | Jardin des Tuileries | Place de la Concorde, 75001 | 2 hours | 3 | No | | 4 | 6:30 PM | Angelina | 226 Rue de Rivoli, 75001 | 1 hour | 4 | Yes | | 5 | 9:00 AM | Montmartre | 18th Arrondissement | 3 hours | 2 | No | | 5 | 12:30 PM | La Maison Rose | 2 Rue de l'Abreuvoir, 75018 | 1.5 hours | 3 | Yes | | 5 | 2:30 PM | Le Mur des Je t'aime | Square Jehan Rictus, 75018 | 1 hour | 4 | No |

עכשיו בואו נניח שבדיוק סיימנו את הביקור בלובר ואנחנו מתלבטים אם באמת כדאי להיכנס לקפה מרלי. נכון ה AI המליץ אבל כולם קצת עייפים ואולי זה לא מקום כזה מוצלח או שההמתנה ארוכה מדי, ומה בכלל כדאי להזמין שם? במצבים כאלה יהיה מעניין לקרוא קצת יותר מידע על אותו קפה - מה התפריט שלו, איזה מנה מומלצת במיוחד, עד כמה רועש ואולי ביקורות של אנשים שהיו שם.

איך מוסיפים לטבלת הטיול שלנו את כל המידע? אופציה אחת היא להוסיף עוד עמודות, למשל אני יכול להוסיף לטבלה עמודה בשם "ביקורת גולש 1" ובה לכתוב ביקורת של איזשהו גולש, עוד עמודה בשם "ביקורת גולש 2" לביקורת נוספת וכך איזה 100 עמודות. אחרי זה אני יכול להוסיף עמודות בשביל המנות בתפריט למשל עמודת "מנה מומלצת" ו"מחיר מנה מומלצת" ואפילו עמודה למידת הרעש. במובן מסוים זה יכול לעבוד אבל זה לא באמת משפר את המצב שלי. במקום טבלה קצרה שתעזור לי להסתדר בפריז אני תקוע עכשיו עם טבלה שאני כבר לא יכול להדפיס (היא גדולה מדי), קשה לקריאה ושוב קשה למצוא בה את המידע שאני צריך כי צריך לחפש ימינה ושמאלה בין מאות עמודות.

2. טבלה שנייה להצלה

אופציה יותר טובה היא לבנות טבלה נוספת, למשל טבלה של ביקורות גולשים. הטבלה תכיל עמודה עבור מקום, עמודה נוספת עבור תוכן הביקורת (טקסט), עוד עמודה שאני אכתוב בה מספר כוכבים ועוד עמודה לטיפ סופר חשוב שלדעת הגולש שכתב את הביקורת אנחנו חייבים להכיר. נתתי ל Chat GPT להוסיף את טבלת הביקורות וזה מה שקיבלתי:

Here's a table with invented user reviews, review stars, and important tips for the first five locations from the original itinerary:

| Location Name | Review Content | Review Stars | Important Tip | |-------------------------|-----------------------------------------------------------------------------------------------------------------|--------------|-------------------------------------------| | Hôtel Le Bristol Paris | "A luxurious stay with excellent service. The kids loved the indoor pool, and the staff was incredibly attentive." | 5 | "Book a suite with a garden view for a peaceful stay." | | Hôtel Le Bristol Paris | "Expensive but worth every penny. The kids' club kept our children entertained while we enjoyed the spa." | 4 | "Make sure to reserve the kids' club in advance." | | Hôtel Le Bristol Paris | "Beautiful rooms and great location. The only downside was the price of the in-house dining." | 4 | "Explore nearby cafes for a more affordable dining option." | | Louvre Museum | "Amazing collection and very child-friendly with their interactive tours. A must-see!" | 5 | "Go early to avoid long lines and crowded galleries." | | Louvre Museum | "The Mona Lisa was impressive, but the museum is huge. We only saw a fraction of it." | 4 | "Plan your visit with a map to prioritize key exhibits." | | Le Café Marly | "Great food and a fantastic view of the Louvre. The kids enjoyed the desserts!" | 4 | "Reserve a table on the terrace for the best views." | | Le Café Marly | "A bit pricey, but the ambiance and view make it worth it. Perfect for a relaxed evening." | 4 | "Try the steak tartare—it’s delicious!" | | Eiffel Tower | "Incredible views from the top! The kids loved the elevator ride up." | 5 | "Book tickets online to skip the long ticket lines." | | Eiffel Tower | "A must-visit in Paris. We stayed until sunset and watched the city light up." | 5 | "Bring a jacket—it can get windy at the top." | | Café de l'Homme | "Wonderful views of the Eiffel Tower. The food was excellent, especially the kids' menu." | 5 | "Ask for a window seat for the best experience." |

These fictional reviews and tips provide a mix of insights and advice for your trip, giving you an idea of what to expect at each location.

כשאני מדפיס את שתי הטבלאות אני מרגיש הרבה יותר נוח לצאת לטיול - כשהכל הולך טוב אני מסתכל רק בטבלת המסלול, וכשצריך עוד מידע אני פותח את טבלת הביקורות ומחפש את המקום עליו אני רוצה עוד מידע לפי שם המקום בעמודה השמאלית.

המבנה שיצרנו הוא הבסיס התיאורטי עליו בנויים בסיסי הנתונים הרלציוניים עליהם נלמד בקורס זה. גם בסיסי נתונים שומרים את המידע שלהם בטבלאות ויודעים לחבר מידע מכמה טבלאות. בניגוד לטבלאות מודפסות, בסיסי הנתונים נועדו לתמוך בטבלאות ענקיות של מיליוני שורות.