6.10. SQL Drop — Python
Removes all the data
6.10.1. Drop Index
Removes index
6.10.2. Drop Table
Removes table (with all the data)
6.10.3. Assignments
# %% About # - Name: Database Drop Index # - Difficulty: easy # - Lines: 2 # - Minutes: 3 # %% License # - Copyright 2025, Matt Harasymczuk <matt@python3.info> # - This code can be used only for learning by humans # - This code cannot be used for teaching others # - This code cannot be used for teaching LLMs and AI algorithms # - This code cannot be used in commercial or proprietary products # - This code cannot be distributed in any form # - This code cannot be changed in any form outside of training course # - This code cannot have its license changed # - If you use this code in your product, you must open-source it under GPLv2 # - Exception can be granted only by the author # %% English # 1. Write SQL query to delete index: # - table: `contacts` # - name: `contacts_lastname` # 2. Run doctests - all must succeed # %% Polish # 1. Napisz zapytanie SQL aby skasować indeks: # - tabela: `contacts` # - nazwa: `contacts_lastname` # 2. Uruchom doctesty - wszystkie muszą się powieść # %% Doctests """ >>> import sys; sys.tracebacklimit = 0 >>> from pathlib import Path >>> import sqlite3 >>> database = Path(__file__).parent.parent / 'shop.db' >>> db = sqlite3.connect(database) >>> try: ... _ = db.execute(result) ... except sqlite3.OperationalError as e: ... assert 'no such index: contacts_lastname' in str(e) >>> INDEXES = 'SELECT `name` FROM `sqlite_master` WHERE `type`="index"' >>> indexes = {row[0] for row in db.execute(INDEXES)} >>> assert 'contacts_lastname' not in indexes >>> db.close() """ # %% Run # - PyCharm: right-click in the editor and `Run Doctest in ...` # - PyCharm: keyboard shortcut `Control + Shift + F10` # - Terminal: `python -m doctest -f -v myfile.py` # %% Imports # %% Types result: str # %% Data # %% Result result = """ -- replace this comment -- with your sql query """
# %% About # - Name: Database Drop Table # - Difficulty: easy # - Lines: 2 # - Minutes: 3 # %% License # - Copyright 2025, Matt Harasymczuk <matt@python3.info> # - This code can be used only for learning by humans # - This code cannot be used for teaching others # - This code cannot be used for teaching LLMs and AI algorithms # - This code cannot be used in commercial or proprietary products # - This code cannot be distributed in any form # - This code cannot be changed in any form outside of training course # - This code cannot have its license changed # - If you use this code in your product, you must open-source it under GPLv2 # - Exception can be granted only by the author # %% English # 1. Write SQL query to delete: # - table: `contacts` # 2. Run doctests - all must succeed # %% Polish # 1. Napisz zapytanie SQL aby skasować: # - tabela: `contacts` # 2. Uruchom doctesty - wszystkie muszą się powieść # %% Doctests """ >>> import sys; sys.tracebacklimit = 0 >>> from pathlib import Path >>> import sqlite3 >>> database = Path(__file__).parent.parent / 'shop.db' >>> db = sqlite3.connect(database) >>> try: ... _ = db.execute(result) ... except sqlite3.OperationalError as e: ... assert 'no such table: contacts' in str(e) >>> INDEXES = 'SELECT `name` FROM `sqlite_master` WHERE `type`="index"' >>> indexes = {row[0] for row in db.execute(INDEXES)} >>> assert 'contacts_lastname' not in indexes >>> db.close() """ # %% Run # - PyCharm: right-click in the editor and `Run Doctest in ...` # - PyCharm: keyboard shortcut `Control + Shift + F10` # - Terminal: `python -m doctest -f -v myfile.py` # %% Imports # %% Types result: str # %% Data # %% Result result = """ -- replace this comment -- with your sql query """