MySql database / table level operations and data types

Database Category

Relational database (SQL): Fixed storage, security

Non-relational databases (NoSQL): storage more flexible, efficient storage of data is relatively high, less secure

 

MySQL is a relational database management system (using the relational model to organize the data in a database system)

 

 

Precautions

Case: no strict distinction between the default capitalization for the program code, lowercase for programmers to write code

The statement terminator: each statement with; or \ g end

Type: Forced type of data, any data type has its own data

Comma: Create a table when the last line does not need a comma

 

 

Entry and Exit

Enter: mysql -uusername -ppassword mysql -uusername -p Enter re-enter the password, the password is not visible

Exit: exit

 

 

Library-level operations

Create a library: create database [if not exists] library name; recreating will complain, you can add if not exists

Delete Library: drop database [if exists] db_name; if you do not know whether there is a database, remember to add if exists

Use database: use db_name;

Show all libraries: show databases;

Query library currently in use: select database ();

 

 

Table-level operations

Displays all the tables: show tables;

Create a table: create table [if not exists] table name (id int, name varchar (20) .....) Repeat to create reports an error, you can add if not exists

Create a table of information display: show create table tb_name;

Delete tables: drop table tb_name

 

 

Operation data in the table

增(insert into values)

Insert the specified field: INSERT INTO tb_name (field_name) VALUES (field_values);

Full field into: INSERT INTO tb_name VALUES (all_values);

A plurality of insert: INSERT INTO tb_name (field_name) VALUES (value_1), (value_2), ...;

 

删(delete from where)

Note: Be sure to write where the conditions, otherwise it will delete all the data in the table

Delete all the data in the table: DELETE FROM tb_name;

Delete the table to meet the conditions of data: DELETE FROM tb_name WHERE conditions;

 

改(update set where)

Note: Be sure to write where conditions are, or will modify all the data in the table

All modified data: UPDATE tb_name SET field_1 = value_1 

Edit multiple: UPDATE tb_name field_1 = value_1 SET, field_2 = value_2 ... WHERE conditions; 

Modifying the data satisfying the condition: UPDATE tb_name SET field_1 = value_1 WHERE conditions; 

 

查(select from where)

Specified field queries: SELECT field_names FROM tb_name;

Full field query: SELECT * FROM tb_name;

Conditional query: SELECT field_names FROM tb_name WHERE conditions; 

 

 

type of data

Numeric types

int four bytes (0,4294967295)

float (m, n) single-precision floating-point (four bytes)

double (m, n) double precision floating point type, m the total number, d decimal places (8 bytes)

Not used: tinyint, samllint, mediumint, bigint

 

Character Types

char (size) stored in fixed-length string (which may include letters, numbers and special characters). Specifies the length of the string in the parenthesis. Up to 255 characters

varchar (size) stored variable length string (which may include letters, numbers and special characters). Specifies the length of the string in the parenthesis. Up to 255 characters. If the length is greater than 255, it will be converted to text type

Not used: tinytext / tinyblob, text / blob, longtext / longblob, enum (enumeration)

 

The date and time type

date: Date Format: 2019-04-16

time: Time Format: 09: 32: 43

datetime: Date Time Format: 2019-04-16 09:32:43

timestamp: automatic storage record modified time

year: in store

 

 

 

Guess you like

Origin www.cnblogs.com/jiyu-hlzy/p/11874148.html