MySQL 简略语法

  • 内容
  • 评论
  • 相关

mysql 简单语法

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
| zst                |
+--------------------+
4 rows in set (0.00 sec)

mysql> show tables;
ERROR 1046 (3D000): No database selected
mysql> use test;
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> use zst;
Database changed
mysql> show tables;
+---------------+
| Tables_in_zst |
+---------------+
| dept          |
| emp           |
+---------------+
2 rows in set (0.00 sec)

mysql> desc emp;
+----------+-------------+------+-----+---------+--
| Field    | Type        | Null | Key | Default | E
+----------+-------------+------+-----+---------+--
| empno    | int(11)     | NO   | PRI |         |
| ename    | varchar(10) | YES  |     | NULL    |
| job      | varchar(10) | YES  |     | NULL    |
| mgr      | int(11)     | YES  |     | NULL    |
| hiredate | datetime    | YES  |     | NULL    |
| sal      | double      | YES  |     | NULL    |
| comm     | double      | YES  |     | NULL    |
| deptno   | int(11)     | YES  | MUL | NULL    |
+----------+-------------+------+-----+---------+--
8 rows in set (0.00 sec)

mysql> desc dept;
+--------+-------------+------+-----+---------+----
| Field  | Type        | Null | Key | Default | Ext
+--------+-------------+------+-----+---------+----
| deptno | int(11)     | NO   | PRI |         |
| dname  | varchar(14) | YES  |     | NULL    |
| loc    | varchar(13) | YES  |     | NULL    |
+--------+-------------+------+-----+---------+----
3 rows in set (0.00 sec)

mysql> insert into dept values(10,'A','A');
Query OK, 1 row affected (0.05 sec)

mysql> insert into dept values(20,'B','B');
Query OK, 1 row affected (0.06 sec)

mysql> insert into dept values(30,'C','C');
Query OK, 1 row affected (0.05 sec)

mysql> insert into dept values(40,'D','D');
Query OK, 1 row affected (0.06 sec)

mysql> insert into dept values(50,'E','E');
Query OK, 1 row affected (0.06 sec)

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from dept;
+--------+-------+------+
| deptno | dname | loc  |
+--------+-------+------+
|     10 | A     | A    |
|     20 | B     | B    |
|     30 | C     | C    |
|     40 | D     | D    |
|     50 | E     | E    |
+--------+-------+------+
5 rows in set (0.00 sec)

mysql> select * from emp;
Empty set (0.00 sec)

mysql> select * from dept limit 3,3
    -> ;
+--------+-------+------+
| deptno | dname | loc  |
+--------+-------+------+
|     40 | D     | D    |
|     50 | E     | E    |
+--------+-------+------+
2 rows in set (0.00 sec)

mysql> create table article(
    -> id int primary key auto_increment,
    -> title varchar(255));
Query OK, 0 rows affected (0.09 sec)

mysql> insert into article values(null,'a');
Query OK, 1 row affected (0.06 sec)

mysql> insert into article values(null,'B');
Query OK, 1 row affected (0.06 sec)

mysql> desc article;
+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id    | int(11)      | NO   | PRI | NULL    | auto_increment |
| title | varchar(255) | YES  |     | NULL    |                |
+-------+--------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

mysql> select * from article;
+----+-------+
| id | title |
+----+-------+
|  1 | a     |
|  2 | B     |
+----+-------+
2 rows in set (0.00 sec)

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2010-12-12 10:18:30 |
+---------------------+
1 row in set (0.00 sec)

mysql> select date_format(now(),'%Y-%m-%d %H:%i%s');
+---------------------------------------+
| date_format(now(),'%Y-%m-%d %H:%i%s') |
+---------------------------------------+
| 2010-12-12 10:2014                    |
+---------------------------------------+
1 row in set (0.00 sec)

mysql> desc emp;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| empno    | int(11)     | NO   | PRI |         |       |
| ename    | varchar(10) | YES  |     | NULL    |       |
| job      | varchar(10) | YES  |     | NULL    |       |
| mgr      | int(11)     | YES  |     | NULL    |       |
| hiredate | datetime    | YES  |     | NULL    |       |
| sal      | double      | YES  |     | NULL    |       |
| comm     | double      | YES  |     | NULL    |       |
| deptno   | int(11)     | YES  | MUL | NULL    |       |
+----------+-------------+------+-----+---------+-------+
8 rows in set (0.00 sec)

原创文章,转载请注明: 转载自搞代码

本文链接地址: MySQL 简略语法

微信支付二维码

微信 赏一包辣条吧~

支付宝支付二维码

支付宝 赏一听可乐吧~

评论

0条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注