The most basic and cheapest basic operation

The basic statement of the database

The following are all under the windows system, first determine whether the database service is open, if not, open the dos command line, type net start mysql, the following figure will appear,
then type mysql -localhost -u (plus your database account ) -p (plus your password);
don't forget the ";" symbol, then enter the password to connect to your database. Next, let's talk about the operation statement on the database. Database statements are not case-sensitive.
Add database: create database (write your database name);
modify database: alter DAtabase
Create new table: create table
Alter table: alter table
Delete table: drop table
Create index (search key): create index
Delete index: drop
index The next step is to add, delete, check, and modify the tables in the database;
⒈ First, let's talk about the query
  select column name from table name and where restrictions (such as id>2, name = 'big head');
  
every time you select table data in the database, it will be Select qualified data from the table, where is used to limit the search conditions, and the results will be stored in a result table (called a result set). Adding distinct before the column name will prevent duplicate data in the output result. Here is how to sort the result set. The order by column name will make the output result set in ascending order according to the column name, and the letters will be arranged in abcd.. , if you want to reverse the order, you need to add the desc keyword after the column name to be arranged in reverse order.
When checking the database, we can also use and and or conditional statements to find,
For example: select *from table name where column name = 'character' and column name = 'character';
if there are conditions on both sides of and in the database, the row of data will be selected, if one of the conditions is not met, then will return empty. And or is that as long as there is a satisfied data on both sides, the data will be selected.
For example, if I am looking for a male Zhang San, this is the use of and to find both a male gender and a name for Zhang San;
and or means that I am looking for Zhang San or a male, this is Zhang San even if it is Women will also be selected, as will men as long as they are.
⒉ The following is to add data
insert into table name values ​​(the data added in the first column, the data added in the second column, ....); of
course, you can also specify the column name,
insert into table name (column 1, column 2, Column 3..) values ​​(the data added in the first column, the data added in the second column, ....);
⒊Modify the data
Use update to modify the data in the
table update table name set column name = new value where is modified Any column name in that row = the value of the column in the row to be modified;
⒋ delete data
Use delete to delete delete from table name where the column name of the data you
want to delete = the data in this row and this column;
delete *from table name; to delete the data of all rows of the table, and will not delete the columns of the table. * can be omitted in this statement.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326529940&siteId=291194637