Coder Social home page Coder Social logo

dor-sketch / sql_sandbox Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 328 KB

A collection of SQL scripts designed to help you improve your SQL querying skills through practical exercises.

PLpgSQL 21.35% Jupyter Notebook 73.37% Python 5.28%
database postgresql sql sqlite

sql_sandbox's Introduction

SQL Sandbox

Overview

This repository is a collection of SQL scripts designed to help you improve your SQL querying skills through practical exercises. It includes scripts for both MySQL and PostgreSQL and features interactive Jupyter notebooks for an engaging learning experience. The exercises are based on the course "20277 Database Systems" at the Open University of Israel.

Content Structure

The repository is organized into four key sections, each with a specific database schema and associated SQL scripts for various practice scenarios:

  1. Gardening Database

    • Schema: Detailed schema for managing gardening data.
    • Contents: Includes scripts for executing all basic SQL queries.
  2. Election Database

    • Schema: Designed for election data management.
    • Contents: Includes comprehensive SQL scripts for typical data retrieval.
  3. Family Database

    • Schema: Basic schema suitable for personal or small-scale applications.
    • Contents: Includes basic SQL queries.
  4. Clinic Database

    • Schema: Initial schema setup for a clinic database.
    • Contents: Currently contains only the schema with plans to add queries.

Additional Resources

The repository also provides various data formats (RDF, XML, and JSON) to facilitate the practice of data manipulation and integration techniques beyond traditional SQL.

Example - Gardening Notebook

Here’s a glimpse into what you can do with the Gardening database using the provided Jupyter notebooks:

Setup

import sqlite3
import readline

# Establish connection to the database
conn = sqlite3.connect('gardening.db')
cursor = conn.cursor()

# Enhance command line interaction
readline.parse_and_bind("tab: complete")
readline.set_history_length(1000)

Function to Execute Queries

def execute_query(query):
    """Execute the given SQL query and display results."""
    try:
        cursor.execute(query)
        results = cursor.fetchall()
        column_names = [desc[0] for desc in cursor.description] if cursor.description else []

        print("Results:")
        if results:
            print("\t".join(column_names))
            for row in results:
                print("\t".join(str(item) for item in row))
        else:
            print("No results found.")
    except sqlite3.Error as error:
        print(f"An error occurred: {error}")

Interactive Query Execution

This section allows users to interactively enter SQL queries and see the results.

try:
    while True:
        query = input("Enter a SQL query (or 'exit' to quit): ")
        if query.lower() == 'exit':
            break
        if query.strip():
            execute_query(query)
finally:
    conn.close()

Contributions

Contributions to this repository are welcome! Feel free to fork the repo and submit pull requests or open issues to suggest improvements.

License

This project is licensed under the MIT License - see the LICENSE file for details.

sql_sandbox's People

Contributors

dor-sketch avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.