Current location - Health Preservation Learning Network - Healthy weight loss - What are the commands for the database?
What are the commands for the database?
1, showing the existing database MySQL >;; Display database;

2. Select the database MySQL >;; Using mysql database has changed (semicolon ending is not required for use and exit commands. ) to display the currently selected database MySQL >;; Select database ();

3. display the table MySQL > existing in the current database. Display table;

4. display the contents of table (db) MySQL >; select * from db

5. Cancel the command When the command is entered incorrectly and cannot be changed (multi-line statement), you can use C to cancel the command before the semicolon appears MySQL >; Select-> User ()-> c

6. Create the database ABCCS MySQL >;; Create database abccs

7. Select database mysql & gt The abccs database has been changed;

8. To create a database table, first look at what tables are in your database now: mysql & gt display table; An empty set (0.00 seconds) means that there are no database tables in the database just established. Let's create a database table mytable: We want to create a birthday table for employees in your company, including their names, gender, date of birth and city of birth. Mytable (name VARCHAR(20), gender CHAR( 1), date of birth, birth addr VARCHAR(20));) is created by mysql >

9. Display the structure of the table: mysql & gt describes my table;

10. Add a record to the table. We first use the SELECT command to view the data in the table: mysql & gtselect * from mytable empty set (0.00 seconds) means that the table just created has not been recorded. Add a new record: mysql & gt inserts mytable values ('abccs',' f',' 1977-07-07',' China');

1 1. It is very troublesome to load data into database tables by text. We can add all records to your database table as text files. Create a text file "mysql.txt", each line contains a record, the values are separated by tabs, and are given in the order of the columns listed in the CREATE TABLE statement. For example: abccs f 1977-07-07 China Mary f 1978- 12 USA Tom m 1970-09-02 USA uses the following command to load the text file "mytable.txt" into mytable: MySQL & loaddata. Then use the following command to see if the data has been entered into the database table: MySQL >;; select * from mytable

12. The format of a SELECT statement to retrieve information from a database table is usually: select a retrieval keyword from the retrieval table where the retrieval condition is located.

13. query all data: mysql & gtselect * from mytable.

14. Correct the wrong record: if tom's birth date is wrong, it should be 1973-09-02, which can be corrected with the update statement: mysql & gt updates mytable collection birth = "1973-09-02" where name = "tom.

15, select a specific column. If you want to see the names of all the people in the table, you can do this: mysql & gt selects the names from my table; If you want to list two columns: name and gender, you can separate the keywords name and birth with commas: myaql & gt Select name and birth from my table.

16. Sorting line We can sort the records in the table by birthday size: mysql & gt Select the name from my table, and sort by birth. We can sort by DESC in reverse order: MySQL >;; Select name, birth from my table, and sort by DESC of birth.

17, the row COUNTing database often needs to count some data, such as the number of employees in the table, so we need to use the row counting function count (). The COUNT () function is used for records with non-empty statistical results: MySQL >;; Select count (*) from mytable; Number of male and female employees: mysql & gtSELECT sex, COUNT(*) FROM mytable GROUP BY sex.

18, multi-table query Now we have two tables: mytable and title. Using these two abccs, we can make a combined query: for example, we want to query the name, gender and article: mysql & gt selects the name, gender and position from my table, where the name = author and the name =' abccs is used to query the author, birthplace and date of birth of article a2: MySQL >; Select the title, author, place of birth and date of birth from my table, and the title-> Where mytable.name=title.writer, title =' a2.

19, add a column: for example, add a column to the mytable table in the above example to indicate whether you are single: MySQL >;; Alter table mytable adds column singlechar (1);

20. modify the record and change the single record of abccs to "y": MySQL >; Update mytableset single =' y' where name =' abccs';

2 1, adding records We have already talked about how to add records. For the convenience of viewing, I repeat: mysql & gt inserts mytable values ('abc',' f',' 1966-08- 17',' China',' n');

22. Delete records Use the following command to delete records in the table: MySQL >;; Delete from mytable, where name =' abcDELETE deletes records from the table that meet the conditions given by where.

23. Delete tables: mysql & gtDrop table * * * table name 1), * * table name 2; You can delete one or more tables, so be careful.

24. Delete the database: mysql & gt Delete the database.