Home > Database > Mysql Tutorial > body text

MySQL常用DDL,DML语句及外键创建

WBOY
Release: 2016-06-07 17:00:26
Original
1155 people have browsed it

Query OK, 0 rows affected (0.05 sec)修改表列类型:ALTER TABLE orderitems MODIFY date DATE;4.插入等(DML): insert into u

1.创建库:
CREATE DATABASE OrderTicket;
Query OK, 1 row affected (0.00 sec)
2.使用库:
mysql> use OrderTicket;
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> use OrderTicket;
Database changed
3.创建表等(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)
修改表列类型:
ALTER TABLE orderitems MODIFY  date DATE;
4.插入等(DML):
insert into users values(004,'004','家源','root','M','15078827641','blues-cen@hotmail.com');
查询,修改,删除等。

5.创建外键:

fights为被参照表,原先没有设置其ENGINE类型,orderitems为参照表。

被参照表中:
1.使用ALTER TABLE fights ENGINE=INNODB.

参照表中:
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)
注意细节问题:
(1)TABLE 的名称不要写成TABEL.
(2)mysql(dos)程序下使用复制粘贴:
选定->标题栏右键编辑->复制,将命令行选定的内容复制到剪切板。
粘贴:复制要粘贴的文本内容到剪切板->标题编辑->粘贴到当前光标输入点。
(3)mysql(dos)插入的位置是在:当前光标的前一个位置插入。
(4)插入可以用VALUES (1,,'***','***'),(2,'**','***');实现多行一次插入。

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template