https://github.com/shaikahmadnawaz/mysql
MySQL is an open-source relational database management system 🗃️
https://github.com/shaikahmadnawaz/mysql
mysql mysql-database rdbms sql
Last synced: about 1 year ago
JSON representation
MySQL is an open-source relational database management system 🗃️
- Host: GitHub
- URL: https://github.com/shaikahmadnawaz/mysql
- Owner: shaikahmadnawaz
- Created: 2023-01-13T10:35:33.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-13T11:50:47.000Z (over 3 years ago)
- Last Synced: 2025-02-17T07:45:32.052Z (over 1 year ago)
- Topics: mysql, mysql-database, rdbms, sql
- Homepage:
- Size: 1.95 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MySQL
## Databases
A database is a structured collection of data
**To create a database:**
```
CREATE DATABASE myDB;
```
There is no case sensitivity in mysql
**To use a database:**
```
USE myDB;
```
**To drop a database:**
```
DROP DATABASE myDB;
```
**Setting a database to read only:**
```
ALTER DATABASE myDB READ ONLY = 1;
```
This statement will make the database read only, if the database is read only mode we cannot make any modifications to the database but we can access the data within.
```
ALTER DATABASE myDB READ ONLY = 0;
```
Now we can do modifications to the database.
## Tables
A table in RDBMS consists of rows and columns.
**We can create a table like this:**
```
CREATE TABLE employees (
employee_id INT,
first_name VARCHAR(50),
last_name VARCHAR(50),
hourly_pay DECIMAL(5, 2),
hire_date DATE
);
```
**we select a table like this:**
```
SELECT * FROM employees;
```
**We can also rename the table:**
```
RENAME TABLE employees TO people;
```
**To drop a table:**
```
DROP TABLE employees;
```
**To alter the table:**
```
ALTER TABLE employees
ADD phone_number VARCHAR(15);
```
**To alter the column name:**
```
ALTER TABLE employees
RENAME COLUMN phone_number TO email;
```
**To change the type of the column:**
```
ALTER TABLE employees
MODIFY COLUMN employee_id VARCHAR(5);
```
**We can also change size of the column:**
```
ALTER TABLE employees
MODIFY COLUMN employee_id VARCHAR(10);
```
**We can also change the position of the columns:**
```
ALTER TABLE employees
MODIFY email VARCHAR(15)
AFTER last_name;
```
**To drop a column:**
```
ALTER TABLE employees
DROP COLUMN hire_date;
```