MySQL basic syntax reference

xiaoxiao2021-04-09  343

Database creation

CREATE DATABASE DATENBANKNAME; // Create a new database, DatenbankName is the library name.

Query database command

Show databases; // Query existing databases to prevent heavy names.

Open the database

Use datenbankname; // Open the database name to DatenbankName.

Delete database

DROP DATABASE DATENBANKNAME; / / Delete Database Name Name DatenbankName

Create a data sheet

Create Table Table_name

Column_name1 Type [Modifiers],

Column_name2 Type [MODIFIERS], ...

);

The // Column column is a single unit of a row of databases in the table.

NOT NULL modifiers indicate that the column cannot contain any NULL values, simply saying that it cannot be empty.

Exception: If the column is defined as Auto_InCrement, the null value will result in an automatically generated value.

The default value is specified for columns.

Delete data table

DROP TABLE TABLE_NAME;

Insert data

INSERT INTO TABLE_NAME (Column1, Column2, ... Columnn)

Values ​​(Value1, Value2, ... Valuen)

Non-standard

INSERT INTO BOOK SET TITLE = 'The Vampire Lestan', Author = 'AnRe Rice';

INSERT INTO FOODS (Name, FAT)

SELECT FOOD_NAME, FAT_GRAMS from Recipes

Plunate the new table by using the data in some other tables (or a set of tables) to insert data.

In this line of grammar, the ORDER BY modifier cannot be included, nor can I choose from INSERT in the table.

delete

Delete from table_name [where clause]

Delete Table1, Table2, ..., Tablen

From Table1, Table2, ..., Tablen

[WHERE CLAUSE]

Inquire

SELECT Colum1, Colum2, ..., Column

From Table1, Table2, ..., Tablen

[WHERE CLAUSE]

Database ()

Returns the name of the current database.

/

Example details

Open the MySQL window

Password input password

If there is no database, new: Here we create a "Datenbank" database

> CREATE DATABASE DATENBANK;

Turn on the database

> Use Datenbank

The newly built data is empty, so the data sheet is to be built, and the name is called UserInfo.

> CREATE TABLE Userinfo

> ID INT (10) Unsigned Auto_INCREMENT NOT NULL, / / ​​Generally, the primary key is used, and each data table is preferably one ID, and automatically assigns. Theunsigned is not negative.

> username varchar (50) Not null, // User name, type VARCHAR, character type, when stored bytes can't exceed 225, and it is taking characters to a few characters, do not automatically.

> Password varchar (50) Not null, //

> Info Blob, / / ​​You can put some big text content.

> JOINDATE VARCHAR (50), // The time stored here, you can use characters, or time type, such as DateTime

> Primary Key (ID)); // Never miss the setting primary key

> ALTER TABLE UserInfo Add text blob; // Add a new field. But in MySQL, you can change a field.

> INSERT INTO UserInfo (Username, Password, Info, Joindate VALUES ('GSSQTN', 'GSSQTN', 'Info', Now ()); // Character type is necessary to add quotation marks, otherwise it will be wrong. this is Insert a new record.> Update UserInfo Set UserName = 'arlene' where id = 1; // Modify the original record, if not, turn the content UserName in the current data table to Arlene.

> delete from userinfo; // Delete content in the data table, if you do not add, completely delete

> delete from userinfo where id = 1; // Delete ID = 1 record

> Select * from userinfo; // View data sheet record, plus conditions can specify a record that meets the eligibility.

> Select * from userinfo order by id; // View data table record, and sorted according to ID, this is small to big. If you want to view, you can add DESC

> Select * from userinfo Oder BY ID LIMIT 0, 10; // View Data Table Record, and sorted by ID and display the previous ten records .limit is the meaning of the limit.

> show tables; / / View the open database has any data table.

> DROP TABLE UserInfo; // Delete Data Sheet UserInfo

转载请注明原文地址:https://www.9cbs.com/read-133151.html

New Post(0)