MySQL common DDL, DML statements, and foreign key Creation

Source: Internet
Author: User
QueryOK, 0 rowsaffected (0.05sec) modify the table column type: ALTERTABLEorderitemsMODIFYdateDATE; 4. insert (DML): insertintou

Query OK, 0 rows affected (0.05 sec) MODIFY the TABLE column type: ALTER TABLE orderitems MODIFY date DATE; 4. insert (DML): insert into u

1. Create a database:
Create database OrderTicket;
Query OK, 1 row affected (0.00 sec)
2. database used:
Mysql> use OrderTicket;
Database changed
Mysql> show tables;
Empty set (0.00 sec)

Mysql> use OrderTicket;
Database changed
3. Create tables (DDL ):
Mysql> create table orderitems (ID int (8) not null auto_increment, FLIGHT_ID BIGINT
(12), date datetime, primary key (ID ))

Query OK, 0 rows affected (0.05 sec)
Modify the table column type:
Alter table orderitems MODIFY date DATE;
4. insert (DML ):
Insert into users values (004, '004 ', 'home source', 'root', 'M', '000000', 'blues-cen@hotmail.com ');
Query, modify, delete, and so on.

5. Create a foreign key:

Fights is the referenced table, and its ENGINE type is not set before. orderitems is the referenced table.

Referenced table:
1. Use alter table fights ENGINE = INNODB.

See the following table:
1. mysql> create table orderitems (id bigint (20) not null AUTO_INCREMENT, fight_id BIGINT (20) not null, date DATETIME, INDEX (fight_id), primary key (ID ), foreign key (fight_id) REFERENCES fights (ID) on delete cascade on update cascade) engine = innodb;

Query OK, 0 rows affected (0.06 sec)
Pay attention to the details:
(1) do not write the TABLE name as TABEL.
(2) Use copy and paste in the mysql (dos) Program:
Select> right-click the title bar and choose Edit> copy to copy the selected content from the command line to the clipboard.
Paste: copy the text to clipboard and edit the title. paste the text to the current cursor Input Point.
(3) mysql (dos) inserts data at the previous position of the current cursor.
(4) You can use VALUES (1, '***', '***'), (2, '***', '***') for insertion ,'**','***'); insert multiple rows at a time.

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.