Skip to content
Pankaj Chouhan edited this page Sep 29, 2023 · 1 revision

Welcome to the SQL-tutorial wiki!

In SQL, you can perform various operations related to databases, such as creating, dropping, selecting, renaming, showing, and backing up databases. Here are examples of SQL commands for each of these operations:

  1. Create Database: To create a new database, you can use the CREATE DATABASE statement.

    CREATE DATABASE mydatabase;
  2. Drop Database: To delete an existing database, you can use the DROP DATABASE statement. Be cautious when using this command, as it permanently deletes the database and its data.

    DROP DATABASE mydatabase;
  3. Select Database: To select a specific database for subsequent SQL operations, use the USE statement.

    USE mydatabase;
  4. Rename Database: SQL does not provide a direct command to rename a database. However, you can achieve this by creating a new database with the desired name and then copying or migrating the data from the old database to the new one. The exact process can vary depending on your database management system (e.g., MySQL, PostgreSQL, SQL Server).

  5. Show Databases: The command to list all available databases can vary depending on your database management system. Here are a few examples:

    • MySQL and MariaDB:

      SHOW DATABASES;
    • PostgreSQL:

      SELECT datname FROM pg_database;
    • SQL Server:

      SELECT name FROM sys.databases;
  6. Backup Database: To create a backup of a database, you typically use database-specific tools or commands. The method varies depending on the database system you're using. Here's a common example using the mysqldump utility for MySQL:

    mysqldump -u username -p mydatabase > backup.sql

    This command exports the database mydatabase to a SQL file named backup.sql. You'll be prompted to enter the password for the database user.

Remember to replace mydatabase with the actual name of your database and username with a valid database user in the examples above. Additionally, database management systems may have their own specific syntax and tools for these operations, so consult the documentation for your specific database system for more details.

Clone this wiki locally