当前位置:网站首页>Some tips on learning database

Some tips on learning database

2022-07-04 10:58:00 Black demon fairy moon

database :
1. Concept : Storage , A warehouse for managing data .
2. Classification of database : Relational database , Non relational database .
MySQL:
1.SQL: Structured query language , Used to query , management , Update the program language of the database .
2. Common operation of database :
1). Common operation of database
Building database

create database fu_shi;
Query OK, 1 row affected (0.001 sec)

Delete library ( Use with caution )

MariaDB [(none)]> drop database cgb210901;
Query OK, 6 rows affected (0.112 sec)

View Library

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| fu_shi             |
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.001 sec)

2) Common operations of tables

The creation of a table

MariaDB [(none)]> create table fu;
ERROR 1046 (3D000): No database selected
MariaDB [(none)]>

You can see , The code above is wrong , Bear in mind , When creating tables in a database, you must not directly create them without specifying the database . The correct way to create a table is as follows :

MariaDB [fu_shi]> use  fu_shi;
Database changed
MariaDB [fu_shi]> create table fu(name varchar(100),age int(10),love varchar(100));
Query OK, 0 rows affected (0.022 sec)

Modify table ----> Add table fields

MariaDB [fu_shi]> alter table fu add column stud varchar (100);
Query OK, 0 rows affected (0.013 sec)

Delete table

MariaDB [fu_shi]> drop table fujia;
Query OK, 0 rows affected (0.018 sec)

View all tables

MariaDB [fu_shi]> show tables;
+------------------+
| Tables_in_fu_shi |
+------------------+
| fu               |
+------------------+
1 row in set (0.001 sec)

View the structure of the table , That is, the fields of the table

MariaDB [fu_shi]> desc fu;
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| name  | varchar(100) | YES  |     | NULL    |       |
| age   | int(10)      | YES  |     | NULL    |       |
| love  | varchar(100) | YES  |     | NULL    |       |
| stud  | varchar(100) | YES  |     | NULL    |       |
+-------+--------------+------+-----+---------+-------+
4 rows in set (0.007 sec)

3) Table records common operations :

insert record

MariaDB [fu_shi]> insert into fu values('fuhah',23,'szh','java');
Query OK, 1 row affected (0.007 sec)

Query log

MariaDB [fu_shi]> select * from fu;
+-------+------+------+------+
| name  | age  | love | stud |
+-------+------+------+------+
| fuhah |   23 | szh  | java |
+-------+------+------+------+
1 row in set (0.000 sec)

Modify the record

MariaDB [fu_shi]> update fu set name='fuhaha';
Query OK, 1 row affected (0.007 sec)
Rows matched: 1  Changed: 1  Warnings: 0

Delete record

MariaDB [fu_shi]> delete from fu ;
Query OK, 1 row affected (0.005 sec)

3. data type
a, Must start with a letter ;
b Different words are separated by underlining ;
c, Don't use keywords :where,group,order;
d,sql Case insensitive , In general ,mysql Use lowercase , Two Oracal Use uppercase
e, When naming, the length should not exceed 30 Characters ;
Naming rules
character
char: The length is immutable , But the reading speed is relatively fast
varchar: Variable length , But the reading speed is slow , More commonly used
Numbers
int ,tinyint: integer
double float: floating-point , But not exactly
numeric decimal: floating-point , Very precise
date :
date: Used to store hours, minutes and seconds
time: Used to store month, year and day
datetime: For MM DD YY , Minutes and seconds
timestamp: For from 1970.1.1.0:00 The number of milliseconds to the specified date
picture
blob Storage path , Not their own files

原网站

版权声明
本文为[Black demon fairy moon]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141412499814.html