MySQL basic syntax summary

I still have to write it non-stop, just thinking about it, even if it is poorly written, at least it will expose my own problems;

In fact, it is still very important to think carefully about the database. Almost all data on the Internet is stored in the database. The common databases are mysql and oracle. Mysql belongs to open source and free software. Most small and medium-sized companies are willing to use mysql as their Own database, this essay summarizes some basic usage in mysql, I think it is mainly divided into 5 parts, database, table itself, table structure and table content and others;

  1. database

    • New database (create database xxx);
    • Query database (show databases);
    • Drop database (drop database xxx);
    • Modify the database (this is to be changed in different ways according to different storage engines, not rename or alter database);
  2. The table itself

    • Query all data tables (show tables);
    • New table (create table xxx (field1 data type, field2 data type));
    • Drop table (drop table xxx);
    • Modify the table name (alter table xxx rename to / as newname);
  3. Table Structure

    • Query table structure (describe / desc table xxx);
    • Query the sql statement that creates the table (show create table xxx);
    • Add a new table column (alter table xxx add yyy data type);
    • Delete columns or primary keys, foreign keys, etc. in the table (alter table xxx drop xxx);
    • Modify the column name (alter table xxx change xxx yyy data type);
    • Modify the column data type (alter table xxx modify xxx data type);
  4. Table content

    • 新增(insert [into] xxx [(field1,field2)] values (d1,d2));
    • Delete (delete from xxx where ...);
    • 修改(update xxx set field=xxx where ...);
    • 查询(select */field1,field2 from xxx [where ...]);
  5. Others
    This essay simply summarizes some basic grammars commonly used in mysql. Of course, there are many other aspects of mysql, such as:

    • Some commonly used functions (count (), max (), min (), avg (), sysdate (), now (), currenttime (), etc.);
    • Conjunction query statement (inner connection, outer connection, self-connection, union, etc.);
    • Storage engine (innodb, myisam, memory, blackhole, etc.);
    • Basic data types and 5 constraints;
    • Transaction (transaction 4 characteristics (Atomicity, Consistency, Isolation, Durability); transaction isolation mechanism, etc.);

Guess you like

Origin www.cnblogs.com/scott1440298847/p/12688975.html