MySQL Database Management
Creating a Database
To create a new database in MySQL, you can use the following SQL command:
CREATE DATABASE your_database_name;
Using a Database
After creating a database, you can use it by executing the following SQL command:
USE your_database_name;
Creating a Table
To create a table in a MySQL database, you can use the following SQL syntax:
CREATE TABLE table_name (
      column1 datatype1 constraints,
      column2 datatype2 constraints,
      ...
    ); 
Example:
CREATE TABLE users (
      id INT AUTO_INCREMENT PRIMARY KEY,
      name VARCHAR(50),
      email VARCHAR(100)
    ); 
Inserting Data
To insert data into a table, you can use the following SQL syntax:
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...); 
Example:
INSERT INTO users (name, email) VALUES ('John Doe', 'john@example.com'); 
Updating Data
To update data in a table, you can use the following SQL syntax:
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition; 
Example:
UPDATE users SET email = 'newemail@example.com' WHERE id = 1; 
Deleting Data
To delete data from a table, you can use the following SQL syntax:
DELETE FROM table_name WHERE condition;
Example:
DELETE FROM users WHERE id = 1; 
Dropping a Table
To drop (delete) a table from the database, you can use the following SQL syntax:
DROP TABLE table_name; 
Example:
DROP TABLE users; 
 

 
    
Top comments (0)