以下是一些常用的MySQL语句:
CREATE DATABASEdatabase_name;
创建一个新数据库。replace database_name with the name of the database you want to create.
USEdatabase_name;
选择要使用的数据库。replace database_name with the name of the database you want to use.
CREATE TABLEtable_name ( column1 datatype, column2 datatype, column3 datatype, ... );
创建新表。replace table_name with the name of the table you want to create, and replace column1, column2, column3, etc. with the names and datatypes of the columns you want to create.
ALTER TABLEtable_nameADD COLUMNcolumn_name datatype;
添加新列。replace table_name with the name of the table you want to alter, and replace column_name and datatype with the name and datatype of the column you want to add.
INSERT INTOtable_name (column1, column2, column3, ...)VALUES(value1, value2, value3, ...);
向表中插入新行。replace table_name with the name of the table you want to insert into, and replace column1, column2, column3, etc. with the names of the columns you want to insert data into. Also replace value1, value2, value3, etc. with the actual values you want to insert.
SELECTcolumn1, column2, ...FROMtable_nameWHEREcondition;
从表中检索数据。replace column1, column2, etc. with the names of the columns you want to retrieve, and replace table_name with the name of the table you want to retrieve data from. Also replace condition with the criteria for the data you want to retrieve.
UPDATEtable_nameSETcolumn1 = value1, column2 = value2, ...WHEREcondition;
更新表中的数据。replace table_name with the name of the table you want to update, and replace column1, column2, etc. with the names of the columns you want to update. Also replace value1, value2, etc. with the new values you want to set in those columns. Finally, replace condition with the criteria for the data you want to update.
DELETE FROMtable_nameWHEREcondition;
从表中删除行。replace table_name with the name of the table you want to delete data from, and replace condition with the criteria for the data you want to delete.
这些是MySQL使用的基本语句。掌握这些语句可以让您更好地管理和查询您的MySQL数据库。