MySQL Learning notes

Source: Internet
Author: User

A short time to learn a few days of MySQL, which is limited to some simple SQL syntax, made a few days of notes, intended 5 days later

Take it up, but because of computer problems, so do not know how to go missing, simply learn a bit, this time I see

Is the MySQL technology insider, feel good, I hope I understand the mistakes in the notes of the place to guide you

First day:

Creating a MySQL Account: Create user ' new username ' @ ' localhost ' identified by ' password ';

Now () displays the date and time of day, user () displays the current users, version () displays the database versions

Use ";" to enter multiple statements on one line: select Now (); select ();

The current database is displayed, select Database () is not the same as show databases, which displays the number of databases in the user and lists them. The former, however, shows the database currently in use. Select Database () is displayed as null when no one is currently in use.

You can use the database directly when you enter MySQL, mysql–p–u user databasename;

Date type "YYYY-MM-DD" in default form date

Auto-Grow type auto_increment, if no value for the column is automatically incremented.

Primary Key (Columns_name), as an index, the primary key

  

Use describe to describe the details of a table

And the same role as the Desc member;explain ...; Show columns from Member;show flelds from member

But show full columns from TABLE_NAME, the entire information of the table, and describe are different meanings.

Specify the type engine= "..." when the table is created, and if not specified, the default type is MyISAM

ENUM (..... ), the value of the data can only be one of the enum: enum (' Y ', ' n ') then the data can only take one of Y or N

Describe can not only describe the results of an entire table, but also describe a single column: Describe table_name ' columns '

PRIMARY Key (student_id,event_id): Two combinations of student_id and event_id as primary keys

Index (): indexed to allow MySQL to search faster

Foreign key (...) references ... The function is to associate the columns in this table with other tables so that score does not produce a nonexistent student_id or event_id;

For why STUDENT_ID has an index, this is because for each data column defined by Froeign, either it is an index itself, or the nature of the index itself, and just primary key itself has an index role, so the first event_id already has the role of the index , but student_id does not have this function, so use index student_id;

  

No dependent tables are created first, Ps:frogign Key...references...references will be created first, and then the preceding is created. If you want to discard the table, the order is exactly the opposite,

Various ways to insert tabular data:

(1) INSERT INTO table_name values (value);

(2) INSERT INTO table_name values (value1), (value2), (...);

(3) INSERT INTO table_name (COLUMN1,COLUMN2), values (' 1_columns ', ' 2_columns ') give the dequeue name, then assign a value (can be multiple or one assignment)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.