Automation Practice Page

Text Fields





Radio Buttons



Checkboxes



Dropdown (Select)

Multi Select Dropdown

Buttons



JavaScript Alerts



File Upload

Date and Time Pickers





Links

Open Google
Go to Bottom

Web Table

ID Name Role
1 Deepesh Trainer
2 Rahul Tester
3 Anita Developer

Iframe

Hidden Element

Enabled & Disabled Fields



Image

Sample Image

Mouse Hover

Bottom of Page

This is the bottom of the page for scrolling practice.

Ultimate Automation Practice Page

Auto Suggestions (Google Style)

AJAX Success & Network Failure

Stale Element Simulation

Drag and Drop

Drag Me


Drop Here

Keyboard Actions

Nested Shadow DOM

Login Page

mysocial

Connect with friends and the world around you on MySocial.

Robot Framework Automation with AI Integration (Beginner to Advanced)

course fee poster


Course highlights

    • Training Mode: Online Zoom Session

    • Duration: 1 Month

    • Recorded sessions are available

    • Daily 1 hr sessions from Monday to Friday.

    • Instructor Name: Deepesh Yadav

Course Content

Module 1: Introduction to Robot Framework

    • Overview of Test Automation

    • Features and Advantages of Robot Framework

    • Installation and Setup (Python, PIP, Robot Framework, IDEs)

    • Directory Structure and Test Suite Organization

    • Writing the First Test Case

    • Executing Tests via Command Line and IDE


Module 2: Core Syntax and Test Structures

    • Test Cases, Keywords, and Variables

    • Settings, Variables, Test Cases, and Keywords Sections

    • Built-In Libraries Overview (String, Collections, DateTime, etc.)

    • Using Tags, Documentation, and Metadata

    • Logging and Reporting


Module 3: Working with SeleniumLibrary

    • Installing and Importing SeleniumLibrary

    • Browser Interaction (Open Browser, Click Element, Input Text, etc.)

    • Locators and XPath Strategies

    • Waits, Timeouts, and Synchronization

    • Handling Alerts, Windows, and Frames

    • Taking Screenshots and Validating UI Elements

    • Cross-Browser Testing


Module 4: API Automation with Robot Framework

    • Introduction to API Testing

    • Working with RequestsLibrary

    • GET, POST, PUT, DELETE Methods

    • Handling Authentication (Basic, Bearer Tokens)

    • Validating JSON/XML Responses

    • Schema Validation

    • Integrating with External Data (CSV, Excel, JSON)


Module 5: AI Integration

    • Overview of AI in Test Automation

    • Integration of ChatGPT, Copilot, and Cursor for Intelligent Test Generation

    • Using AI to Auto-Generate Test Cases and Keywords

    • AI-driven Code Suggestions in PyCharm and VS Code

    • Automating Test Documentation with AI

    • Integrating AI Chatbots with Robot Framework

    • Smart Error Analysis using AI Models


Module 6: GitHub and Version Control Integration

    • Git Basics and Repository Setup

    • Pushing and Pulling Robot Test Projects

    • Branching, Merging, and Conflict Resolution

    • Integrating GitHub Actions with Robot Framework

    • CI/CD Pipeline Overview


Module 7: PyCharm Integration

    • Installing and Configuring PyCharm for Robot Framework

    • Plugins and Run Configurations

    • Debugging Robot Tests in PyCharm

    • Code Completion and Keyword Assistance

    • Integrating AI Tools (Copilot, Cursor, ChatGPT in PyCharm)


Module 8: Data-Driven and Keyword-Driven Frameworks

    • Creating Reusable Custom Keywords

    • Working with Resource Files

    • Using Variables and Dynamic Test Data

    • Reading Data from Excel, CSV, JSON

    • Implementing Keyword-Driven Frameworks

    • Parameterized and Loop-Driven Test Cases


Module 9: Advanced Framework Design

    • Designing Scalable Automation Frameworks

    • Modular Test Architecture

    • Error Handling and Retry Logic

    • Parallel Test Execution (Pabot Integration)

    • Custom Library Development in Python

    • Integrating Database Testing

    • Working with API + UI Combined Tests


Module 10: CI/CD and Jenkins Integration

    • Jenkins Overview and Setup

    • Creating Jenkins Pipeline for Robot Tests

    • Running Tests from GitHub via Jenkins

    • Generating HTML Reports in Jenkins

    • Automated Notifications (Slack/Email Integration)

    • Using Docker Containers for Test Execution


Module 11: Reporting and Analytics

    • Default Robot Framework Reports and Logs

    • Generating Custom HTML Reports

    • Integrating with Allure Reports

    • Visualizing Test Metrics

    • AI-based Test Report Analysis


Module 12: Real-World Projects

    • End-to-End Web Application Automation

    • REST API + UI Automation Combined Framework

    • Continuous Integration Pipeline Project

    • AI-Assisted Automation Project using ChatGPT API


Module 13: Best Practices and Interview Preparation

    • Framework Design Best Practices

    • Common Interview Questions for Robot Framework and Python Automation

    • Industry Use Cases and Portfolio Building

    • Live Project to automate end-to-end Scenarios and Integration with CI/CD Pipeline.

Students Feedback

Join tuples with the same first element

Python Practice › Tuple Programs › Program 17

Join tuples with the same first element

MediumTuple Programs · 17 of 70

Write a Python program to join tuples that start with the same element.

Input
[(3, 6, 7), (7, 8, 4), (7, 3), (3, 0, 5)]
Output
[(3, 6, 7, 0, 5), (7, 8, 4, 3)]

Approach

  1. Group by the first element in a dict, appending the rest of each tuple.

Solution

Python
data = [(3, 6, 7), (7, 8, 4), (7, 3), (3, 0, 5)]groups = {}for first, *rest in data:    groups.setdefault(first, [first]).extend(rest)print([tuple(v) for v in groups.values()])
Output
[(3, 6, 7, 0, 5), (7, 8, 4, 3)]

Line by line

Line 3

first, *rest splits each tuple into its first item and the remaining items.

Line 4

The first time a key appears, its list starts as [first]; later tuples only add their remaining items.

Learn the concept

New to this topic? Read the lesson, then come back.

More tuple programs

← All 70 Tuple Programs

Add values row by row to a tuple matrix

Python Practice › Tuple Programs › Program 14

Add values row by row to a tuple matrix

MediumTuple Programs · 14 of 70

Write a Python program to add one value from a tuple to each row of a tuple matrix.

Input
A = [[("sqa", 4)], [("tools", 8)]], B = (3, 6)
Output
[[('sqa', 4, 3)], [('tools', 8, 6)]]

Approach

  1. Pair each row with its value using zip, then extend every tuple in the row.

Solution

Python
A = [[("sqa", 4)], [("tools", 8)]]B = (3, 6)result = [[t + (value,) for t in row] for row, value in zip(A, B)]print(result)
Output
[[('sqa', 4, 3)], [('tools', 8, 6)]]

Line by line

Line 3

zip(A, B) pairs the first row with 3 and the second with 6; each tuple gets that value appended.

Learn the concept

New to this topic? Read the lesson, then come back.

More tuple programs

← All 70 Tuple Programs

Dummy Booking Website

Practice end-to-end flight booking for automation testing: log in, search flights, pick a flight and seats, enter passenger details and pay with dummy test data. Every element has a stable id and data-testid for Selenium and Playwright practice.

Dummy Ticket Booking Website

SkyTrip practice airline: a safe, fake booking flow for automation testing. No real flights or payments.
Signed in as Test User
  1. 1Search
  2. 2Select flight
  3. 3Passengers
  4. 4Seats
  5. 5Payment
  6. 6Confirmation

Select your flight

Traveller details

Enter names exactly as on the passport or ID. All fields marked * are required.

Contact details

Choose your seats

Pick a seat for each traveller on each flight. Infants sit on an adult’s lap.

FreeExtra legroom ₹800 OccupiedSelected traveller Your other travellers

Review and pay

This is a dummy payment. Only the test details listed below are accepted.

Practice only: use card 4111 1111 1111 1111, UPI success@upi or any bank. Do not enter real card details.
Processing payment…

is_selected Method

The is_selected() method in Selenium is used to check whether a web element, such as a checkbox, radio button, or option in a dropdown, is currently selected or not. It returns True if the element is selected and False if it is not.

Syntax:

element.is_selected()

Example:

from selenium import webdriver
from selenium.webdriver.common.by import By

#
Set up the driver (assuming you're using Chrome)
driver = webdriver.Chrome()

#
Open a webpage with website example
driver.get('https://example.com')

#
Locate a checkbox or radio button element
checkbox = driver.find_element(By.ID, 'checkbox_id')

#
Check if the checkbox is selected
if checkbox.is_selected():
print("The checkbox is selected.")
else:
print("The checkbox is not selected.")

#
Close the browser
driver.quit()

Example with checkbox selection

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()

driver.implicitly_wait(20)
driver.maximize_window()

#
Open dummy website on the browser
driver.get('
https://sqatools.in/dummy-booking-website/')

#
get the "Remember me" checkbox
checkbox_element = driver.find_element(By.ID, "remember-me")

#
check is_selected status before selecting checkbox
print("is_selected status:", checkbox_element.is_selected()) # False

checkbox_element.click()

#
check is_selected status after selecting checkbox
print("is_selected status:", checkbox_element.is_selected()) # True

#
Close browser
driver.quit()


Explanation:

  • element.is_selected() works primarily for form elements like checkboxes, radio buttons, and options within a <select> dropdown.

  • If the element is selected (checked for a checkbox, selected for a radio button or dropdown option), it returns True. Otherwise, it returns False.

This method is useful when you need to verify the state of form elements before taking further action.


SQL REVOKE Statement

SQL Tutorial › Security › REVOKE

SQL REVOKE Statement

IntermediateLesson 68 of 697 min read5 queries run on MySQL 8.4

REVOKE is the opposite of GRANT: it takes privileges away from an account or role. You need it when someone changes team, when an application no longer needs write access, or after an audit finds an account with too much power. The privileges are removed immediately.

In this lesson
  • Revoke individual privileges and all privileges
  • Revoke roles and the grant option
  • Verify with SHOW GRANTS
  • Avoid the “revoke at a different level” trap

REVOKE syntax

MySQL
REVOKE privilege [, privilege ...]ON levelFROM 'user'@'host';

The level must match how the privilege was granted (company.*, company.orders, …).

Revoke one privilege

The shop application should no longer delete rows (it uses soft deletes now):

MySQL
CREATE USER 'shop_app'@'localhost' IDENTIFIED BY 'Sh0p#App2026';GRANT SELECT, INSERT, UPDATE, DELETE ON company.* TO 'shop_app'@'localhost';REVOKE DELETE ON company.* FROM 'shop_app'@'localhost';SHOW GRANTS FOR 'shop_app'@'localhost';
ResultMySQL 8.4
mysql> CREATE USER 'shop_app'@'localhost' IDENTIFIED BY 'Sh0p
Query OK, 0 rows affected
mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON company.* TO 'shop_app'@'local…
Query OK, 0 rows affected
mysql> REVOKE DELETE ON company.* FROM 'shop_app'@'localhost'
Query OK, 0 rows affected
mysql> SHOW GRANTS FOR 'shop_app'@'localhost'
Grants for shop_app@localhost
GRANT USAGE ON *.* TO `shop_app`@`localhost`
GRANT SELECT, INSERT, UPDATE ON `company`.* TO `shop_app`@`localhost`
2 rows in set
How this query works, step by step
  1. The account starts with four privileges on company.*.
  2. REVOKE DELETE removes one; SHOW GRANTS now lists SELECT, INSERT, UPDATE.
  3. The change applies to new statements immediately, even in sessions that are already connected.

Revoke everything

MySQL
CREATE USER 'contractor'@'localhost' IDENTIFIED BY 'C0ntract#2026';GRANT SELECT, INSERT ON company.* TO 'contractor'@'localhost';GRANT SELECT ON company.employees TO 'contractor'@'localhost';REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'contractor'@'localhost';SHOW GRANTS FOR 'contractor'@'localhost';
ResultMySQL 8.4
mysql> CREATE USER 'contractor'@'localhost' IDENTIFIED BY 'C0ntract
Query OK, 0 rows affected
mysql> GRANT SELECT, INSERT ON company.* TO 'contractor'@'localhost'
Query OK, 0 rows affected
mysql> GRANT SELECT ON company.employees TO 'contractor'@'localhost'
Query OK, 0 rows affected
mysql> REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'contractor'@'localhost'
Query OK, 0 rows affected
mysql> SHOW GRANTS FOR 'contractor'@'localhost'
Grants for contractor@localhost
GRANT USAGE ON *.* TO `contractor`@`localhost`
1 row in set
How this query works, step by step
  1. The contractor had privileges at two levels: database and table.
  2. REVOKE ALL PRIVILEGES, GRANT OPTION FROM ... (without ON) removes them at every level.
  3. Only USAGE remains: the account can log in but do nothing. To remove the account completely, DROP USER.

The level trap

A privilege granted at database level cannot be revoked for one table:

MySQL
CREATE USER 'analyst1'@'localhost' IDENTIFIED BY 'An@lyst2026';GRANT SELECT ON company.* TO 'analyst1'@'localhost';REVOKE SELECT ON company.employees FROM 'analyst1'@'localhost';
ResultMySQL 8.4
mysql> CREATE USER 'analyst1'@'localhost' IDENTIFIED BY 'An@lyst2026'
Query OK, 0 rows affected
mysql> GRANT SELECT ON company.* TO 'analyst1'@'localhost'
Query OK, 0 rows affected
mysql> REVOKE SELECT ON company.employees FROM 'analyst1'@'localhost'
ERROR 1147 (42000): There is no such grant defined for user 'analyst1' on host 'localhost' on table 'employees'
How this query works, step by step
  1. SELECT was granted on company.*, not on company.employees.
  2. There is no table-level grant to remove, so MySQL reports error 1147.
  3. To give “all tables except employees”, revoke the database grant and grant SELECT table by table (or through views).

Revoke a role

MySQL
CREATE ROLE 'analyst';GRANT SELECT ON company.* TO 'analyst';CREATE USER 'priya'@'localhost' IDENTIFIED BY 'Pr1ya#2026';GRANT 'analyst' TO 'priya'@'localhost';REVOKE 'analyst' FROM 'priya'@'localhost';SHOW GRANTS FOR 'priya'@'localhost';
ResultMySQL 8.4
mysql> CREATE ROLE 'analyst'
Query OK, 0 rows affected
mysql> GRANT SELECT ON company.* TO 'analyst'
Query OK, 0 rows affected
mysql> CREATE USER 'priya'@'localhost' IDENTIFIED BY 'Pr1ya
Query OK, 0 rows affected
mysql> GRANT 'analyst' TO 'priya'@'localhost'
Query OK, 0 rows affected
mysql> REVOKE 'analyst' FROM 'priya'@'localhost'
Query OK, 0 rows affected
mysql> SHOW GRANTS FOR 'priya'@'localhost'
Grants for priya@localhost
GRANT USAGE ON *.* TO `priya`@`localhost`
1 row in set

Changing the role itself (REVOKE INSERT ON company.* FROM 'developer';) changes the access of every account that has the role.

Revoke the grant option

MySQL
CREATE USER 'team_lead'@'localhost' IDENTIFIED BY 'L3ad#2026';GRANT SELECT ON company.* TO 'team_lead'@'localhost' WITH GRANT OPTION;REVOKE GRANT OPTION ON company.* FROM 'team_lead'@'localhost';SHOW GRANTS FOR 'team_lead'@'localhost';
ResultMySQL 8.4
mysql> CREATE USER 'team_lead'@'localhost' IDENTIFIED BY 'L3ad
Query OK, 0 rows affected
mysql> GRANT SELECT ON company.* TO 'team_lead'@'localhost' WITH GRANT OPTION
Query OK, 0 rows affected
mysql> REVOKE GRANT OPTION ON company.* FROM 'team_lead'@'localhost'
Query OK, 0 rows affected
mysql> SHOW GRANTS FOR 'team_lead'@'localhost'
Grants for team_lead@localhost
GRANT USAGE ON *.* TO `team_lead`@`localhost`
GRANT SELECT ON `company`.* TO `team_lead`@`localhost`
2 rows in set

The team lead keeps SELECT but can no longer give it to others.

Quick quiz

1. How do you remove all privileges of an account at every level?

2. SELECT was granted ON company.*. What happens with REVOKE SELECT ON company.orders?

3. Does a REVOKE affect sessions that are already connected?

REVOKE FAQ

What is the difference between GRANT and REVOKE?

GRANT gives privileges to an account or role; REVOKE removes them.

How do I remove all privileges from a MySQL user?

REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'user'@'host'; The account keeps only USAGE. Use DROP USER to delete it.

Why does REVOKE give error 1141 or 1147?

The privilege was not granted at the level you named. Check with SHOW GRANTS and revoke at the same level (db.*, db.table or global).

SQL GRANT Statement

SQL Tutorial › Security › GRANT

SQL GRANT Statement

IntermediateLesson 67 of 6910 min read7 queries run on MySQL 8.4

GRANT gives an account (or a role) permission to do something: read a table, insert rows, create tables, run a procedure. It is the core of DCL (Data Control Language). Granting exactly what each account needs, and nothing more, is the most effective database security measure you can take.

In this lesson
  • Grant privileges at global, database, table and column level
  • Inspect privileges with SHOW GRANTS
  • Grant through views for row and column security
  • Understand WITH GRANT OPTION and ALL PRIVILEGES

GRANT syntax

MySQL
GRANT privilege [, privilege ...]ON levelTO 'user'@'host' [, ...][WITH GRANT OPTION];
LevelWritten asExample
Global.every database on the server
Databasecompany.*every table in company
Tablecompany.ordersone table
ColumnSELECT (col1, col2) ON company.employeessome columns of one table
RoutineEXECUTE ON PROCEDURE company.place_orderone procedure

Common privileges: SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, INDEX, EXECUTE, CREATE VIEW, TRIGGER, and ALL PRIVILEGES.

Database-level grant

MySQL
CREATE USER 'shop_app'@'localhost' IDENTIFIED BY 'Sh0p#App2026';GRANT SELECT, INSERT, UPDATE, DELETE ON company.* TO 'shop_app'@'localhost';SHOW GRANTS FOR 'shop_app'@'localhost';
ResultMySQL 8.4
mysql> CREATE USER 'shop_app'@'localhost' IDENTIFIED BY 'Sh0p
Query OK, 0 rows affected
mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON company.* TO 'shop_app'@'local…
Query OK, 0 rows affected
mysql> SHOW GRANTS FOR 'shop_app'@'localhost'
Grants for shop_app@localhost
GRANT USAGE ON *.* TO `shop_app`@`localhost`
GRANT SELECT, INSERT, UPDATE, DELETE ON `company`.* TO `shop_app`@`localhost`
2 rows in set
How this query works, step by step
  1. The account can read and change rows in every table of company.
  2. It cannot create, alter or drop tables, and it cannot touch other databases.
  3. SHOW GRANTS lists exactly what the account may do.

Table-level grant

A reporting account that may read only the shop tables:

MySQL
CREATE USER 'report_reader'@'localhost' IDENTIFIED BY 'Rep0rt#2026';GRANT SELECT ON company.orders TO 'report_reader'@'localhost';GRANT SELECT ON company.order_items TO 'report_reader'@'localhost';GRANT SELECT ON company.products TO 'report_reader'@'localhost';SHOW GRANTS FOR 'report_reader'@'localhost';
ResultMySQL 8.4
mysql> CREATE USER 'report_reader'@'localhost' IDENTIFIED BY 'Rep0rt
Query OK, 0 rows affected
mysql> GRANT SELECT ON company.orders TO 'report_reader'@'localhost'
Query OK, 0 rows affected
mysql> GRANT SELECT ON company.order_items TO 'report_reader'@'localhost'
Query OK, 0 rows affected
mysql> GRANT SELECT ON company.products TO 'report_reader'@'localhost'
Query OK, 0 rows affected
mysql> SHOW GRANTS FOR 'report_reader'@'localhost'
Grants for report_reader@localhost
GRANT USAGE ON *.* TO `report_reader`@`localhost`
GRANT SELECT ON `company`.`order_items` TO `report_reader`@`localhost`
GRANT SELECT ON `company`.`orders` TO `report_reader`@`localhost`
GRANT SELECT ON `company`.`products` TO `report_reader`@`localhost`
4 rows in set

Column-level grant

HR assistants may see employee names and departments, but not salaries:

MySQL
CREATE USER 'hr_assistant'@'localhost' IDENTIFIED BY 'Hr#Asst2026';GRANT SELECT (emp_id, first_name, last_name, dept_id, job_title) ON company.employees TO 'hr_assistant'@'localhost';GRANT UPDATE (job_title) ON company.employees TO 'hr_assistant'@'localhost';SHOW GRANTS FOR 'hr_assistant'@'localhost';
ResultMySQL 8.4
mysql> CREATE USER 'hr_assistant'@'localhost' IDENTIFIED BY 'Hr
Query OK, 0 rows affected
mysql> GRANT SELECT (emp_id, first_name, last_name, dept_id, job_title) ON co…
Query OK, 0 rows affected
mysql> GRANT UPDATE (job_title) ON company.employees TO 'hr_assistant'@'local…
Query OK, 0 rows affected
mysql> SHOW GRANTS FOR 'hr_assistant'@'localhost'
Grants for hr_assistant@localhost
GRANT USAGE ON *.* TO `hr_assistant`@`localhost`
GRANT SELECT (`dept_id`, `emp_id`, `first_name`, `job_title`, `last_name`), UPDATE (`job_title`) ON `company`.`employees` TO `hr_assistant`@`localhost`
2 rows in set
How this query works, step by step
  1. SELECT (columns) allows reading only the listed columns; SELECT salary FROM employees would fail for this account.
  2. UPDATE (job_title) allows changing that one column only.

Security through views

Column grants cannot filter rows. A view can: give a regional manager only Mumbai employees:

MySQL
CREATE VIEW mumbai_staff ASSELECT emp_id, first_name, last_name, job_title FROM employees WHERE city = 'Mumbai';CREATE USER 'mumbai_mgr'@'localhost' IDENTIFIED BY 'Mumb@i#2026';GRANT SELECT ON company.mumbai_staff TO 'mumbai_mgr'@'localhost';SHOW GRANTS FOR 'mumbai_mgr'@'localhost';
ResultMySQL 8.4
mysql> CREATE VIEW mumbai_staff AS
Query OK, 0 rows affected
mysql> CREATE USER 'mumbai_mgr'@'localhost' IDENTIFIED BY 'Mumb@i
Query OK, 0 rows affected
mysql> GRANT SELECT ON company.mumbai_staff TO 'mumbai_mgr'@'localhost'
Query OK, 0 rows affected
mysql> SHOW GRANTS FOR 'mumbai_mgr'@'localhost'
Grants for mumbai_mgr@localhost
GRANT USAGE ON *.* TO `mumbai_mgr`@`localhost`
GRANT SELECT ON `company`.`mumbai_staff` TO `mumbai_mgr`@`localhost`
2 rows in set

The account can read the view but has no privilege on employees itself (Views).

Grant to a role

MySQL
CREATE ROLE 'qa_tester';GRANT SELECT, INSERT, UPDATE, DELETE ON company.* TO 'qa_tester';CREATE USER 'arjun'@'localhost' IDENTIFIED BY 'Arj#un2026';GRANT 'qa_tester' TO 'arjun'@'localhost';SHOW GRANTS FOR 'arjun'@'localhost';
ResultMySQL 8.4
mysql> CREATE ROLE 'qa_tester'
Query OK, 0 rows affected
mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON company.* TO 'qa_tester'
Query OK, 0 rows affected
mysql> CREATE USER 'arjun'@'localhost' IDENTIFIED BY 'Arj
Query OK, 0 rows affected
mysql> GRANT 'qa_tester' TO 'arjun'@'localhost'
Query OK, 0 rows affected
mysql> SHOW GRANTS FOR 'arjun'@'localhost'
Grants for arjun@localhost
GRANT USAGE ON *.* TO `arjun`@`localhost`
GRANT `qa_tester`@`%` TO `arjun`@`localhost`
2 rows in set

See Users & Roles.

WITH GRANT OPTION and ALL PRIVILEGES

  • WITH GRANT OPTION lets the account pass its own privileges on to others. Give it only to administrators.
  • GRANT ALL PRIVILEGES ON company.* TO ... gives every database-level privilege, including DROP. Convenient for a developer’s own test database, dangerous for an application account.
MySQL
CREATE USER 'team_lead'@'localhost' IDENTIFIED BY 'L3ad#2026';GRANT ALL PRIVILEGES ON company.* TO 'team_lead'@'localhost' WITH GRANT OPTION;SHOW GRANTS FOR 'team_lead'@'localhost';
ResultMySQL 8.4
mysql> CREATE USER 'team_lead'@'localhost' IDENTIFIED BY 'L3ad
Query OK, 0 rows affected
mysql> GRANT ALL PRIVILEGES ON company.* TO 'team_lead'@'localhost' WITH GRAN…
Query OK, 0 rows affected
mysql> SHOW GRANTS FOR 'team_lead'@'localhost'
Grants for team_lead@localhost
GRANT USAGE ON *.* TO `team_lead`@`localhost`
GRANT ALL PRIVILEGES ON `company`.* TO `team_lead`@`localhost` WITH GRANT OPTION
2 rows in set

Errors

Granting on an account that does not exist fails in MySQL 8 (older versions silently created it):

MySQL
GRANT SELECT ON company.* TO 'ghost'@'localhost';
ResultMySQL 8.4
ERROR 1410 (42000): You are not allowed to create a user with GRANT

Quick quiz

1. What does ON company.* mean?

2. How do you let an account read only some columns of a table?

3. Which tool restricts which rows an account can see?

4. What does WITH GRANT OPTION allow?

GRANT FAQ

What is the GRANT command in SQL?

A Data Control Language statement that gives privileges, such as SELECT or INSERT, on databases, tables, columns or routines to accounts or roles.

How do I see the privileges of a MySQL user?

SHOW GRANTS FOR 'user'@'host'; For your own account, SHOW GRANTS;.

Do I need FLUSH PRIVILEGES after GRANT?

No. GRANT, REVOKE, CREATE USER and similar statements take effect immediately. FLUSH PRIVILEGES is only needed after editing the grant tables directly, which you should not do.

SQL DROP TABLE and DROP DATABASE

SQL Tutorial › Database Design › DROP TABLE & DATABASE

SQL DROP TABLE and DROP DATABASE

BeginnerLesson 58 of 697 min read7 queries run on MySQL 8.4

DROP removes a database object completely: the table’s structure, data, indexes and triggers, or a whole database with every table in it. It is instant and cannot be undone with ROLLBACK, so it is the one command where a typo hurts most. This lesson shows how to drop safely.

In this lesson
  • Remove a table with DROP TABLE
  • Make scripts re-runnable with IF EXISTS
  • Drop tables that are referenced by foreign keys
  • Drop a database, and compare DROP, TRUNCATE and DELETE

DROP TABLE

MySQL
CREATE TABLE temp_report (id INT, total INT);SHOW TABLES LIKE 'temp%';DROP TABLE temp_report;SHOW TABLES LIKE 'temp%';
ResultMySQL 8.4
mysql> CREATE TABLE temp_report (id INT, total INT)
Query OK, 0 rows affected
mysql> SHOW TABLES LIKE 'temp%'
Tables_in_company (temp%)
temp_report
1 row in set
mysql> DROP TABLE temp_report
Query OK, 0 rows affected
mysql> SHOW TABLES LIKE 'temp%'
Empty set
How this query works, step by step
  1. The table is created and SHOW TABLES lists it.
  2. DROP TABLE removes the table and all its rows.
  3. The second SHOW TABLES returns an Empty set.

IF EXISTS

Dropping a table that does not exist is an error:

MySQL
DROP TABLE no_such_table;
ResultMySQL 8.4
ERROR 1051 (42S02): Unknown table 'company.no_such_table'

IF EXISTS turns it into a note, so setup scripts can run again and again:

MySQL
DROP TABLE IF EXISTS no_such_table;SHOW WARNINGS;
ResultMySQL 8.4
mysql> DROP TABLE IF EXISTS no_such_table
Query OK, 0 rows affected, 1 warning
mysql> SHOW WARNINGS
LevelCodeMessage
Note1051Unknown table 'company.no_such_table'
1 row in set

Several tables at once

MySQL
CREATE TABLE t1 (a INT);CREATE TABLE t2 (a INT);DROP TABLE IF EXISTS t1, t2;SHOW TABLES LIKE 't_';
ResultMySQL 8.4
mysql> CREATE TABLE t1 (a INT)
Query OK, 0 rows affected
mysql> CREATE TABLE t2 (a INT)
Query OK, 0 rows affected
mysql> DROP TABLE IF EXISTS t1, t2
Query OK, 0 rows affected
mysql> SHOW TABLES LIKE 't_'
Empty set

Tables referenced by foreign keys

A parent table cannot be dropped while a child table references it:

MySQL
DROP TABLE customers;
ResultMySQL 8.4
ERROR 3730 (HY000): Cannot drop table 'customers' referenced by a foreign key constraint 'orders_ibfk_1' on table 'orders'.

Drop the child first, then the parent:

MySQL
DROP TABLE order_items;DROP TABLE orders;DROP TABLE customers;SHOW TABLES;
ResultMySQL 8.4
mysql> DROP TABLE order_items
Query OK, 0 rows affected
mysql> DROP TABLE orders
Query OK, 0 rows affected
mysql> DROP TABLE customers
Query OK, 0 rows affected
mysql> SHOW TABLES
Tables_in_company
departments
employees
products
3 rows in set
How this query works, step by step
  1. order_items references orders, and orders references customers.
  2. Dropping in child-to-parent order satisfies every foreign key.
  3. The three tables are gone; departments, employees and products remain.
Watch out

You may see scripts that run SET FOREIGN_KEY_CHECKS = 0; to drop tables in any order. That also lets broken data in, so use it only in throw-away development databases and switch it back on immediately.

DROP DATABASE

MySQL
CREATE DATABASE scratch_db;DROP DATABASE scratch_db;DROP DATABASE IF EXISTS scratch_db;SHOW DATABASES;
ResultMySQL 8.4
mysql> CREATE DATABASE scratch_db
Query OK, 1 row affected
mysql> DROP DATABASE scratch_db
Query OK, 0 rows affected
mysql> DROP DATABASE IF EXISTS scratch_db
Query OK, 0 rows affected, 1 warning
mysql> SHOW DATABASES
Database
information_schema
mysql
performance_schema
sys
4 rows in set
How this query works, step by step
  1. DROP DATABASE deletes the database and every table in it: Query OK, 0 rows affected (the count is the number of tables dropped).
  2. Running it again with IF EXISTS produces only a warning.

DROP vs TRUNCATE vs DELETE

DROP TABLETRUNCATE TABLEDELETE FROM
Removes datayesyes, all rowschosen rows
Removes structureyesnono
Can use WHEREnonoyes
Can be rolled backnonoyes
Fires DELETE triggersnonoyes

Safety checklist

  1. Run SELECT DATABASE(); to be sure which database you are in.
  2. Take a backup (mysqldump) of anything you might need.
  3. Prefer renaming (RENAME TABLE orders TO orders_old_2026) and dropping later, once nobody has complained.
  4. In production, grant the DROP privilege only to the accounts that need it (GRANT).

Quick quiz

1. What does DROP TABLE remove?

2. Why use DROP TABLE IF EXISTS in scripts?

3. In which order must you drop orders and customers?

DROP FAQ

What is the difference between DROP and TRUNCATE?

DROP TABLE deletes the table completely, structure included. TRUNCATE TABLE deletes all rows but keeps the empty table.

Can I undo DROP TABLE?

Not with ROLLBACK. Restore from a backup or point-in-time recovery using the binary log.

How do I drop a table with a foreign key?

Drop the referencing (child) tables first, or remove the foreign key with ALTER TABLE child DROP FOREIGN KEY name;.