sql笔记(待整理)

Last login: Tue Feb 28 19:59:11 on console

bogon:~ tinghou$ mysql -u root -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 15

Server version: 5.6.12 MySQL Community Server (GPL)


Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| day05              |

| day06              |

| day07              |

| mysql              |

| performance_schema |

| studyMysql         |

| test               |

| testdb             |

| textdb1            |

+--------------------+

10 rows in set (0.01 sec)


mysql> use day07;

Database changed

mysql> show tables;

Empty set (0.00 sec)


mysql> use day06;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A


Database changed

mysql> show tables;

+-----------------+

| Tables_in_day06 |

+-----------------+

| emp             |

| stu             |

| users           |

+-----------------+

3 rows in set (0.00 sec)


mysql> desc users;

+----------+-------------+------+-----+---------+----------------+

| Field    | Type        | Null | Key | Default | Extra          |

+----------+-------------+------+-----+---------+----------------+

| id       | int(11)     | NO   | PRI | NULL    | auto_increment |

| name     | varchar(40) | YES  |     | NULL    |                |

| password | varchar(40) | YES  |     | NULL    |                |

| email    | varchar(60) | YES  |     | NULL    |                |

| birthday | date        | YES  |     | NULL    |                |

+----------+-------------+------+-----+---------+----------------+

5 rows in set (0.01 sec)


mysql> select * frome users;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'frome users' at line 1

mysql> select *from users;

+----+------+----------+-------------+------------+

| id | name | password | email       | birthday   |

+----+------+----------+-------------+------------+

|  1 | zs   | 123456   | [email protected] | 1980-12-04 |

|  2 | ls   | 123      | [email protected] | 1990-01-01 |

+----+------+----------+-------------+------------+

2 rows in set (0.00 sec)


mysql> create table sort(

    -> sid int primary key,

    -> sname varchar(50),

    -> sprice double,

    -> sdesc varchar(50)

    -> )

    -> 

    -> ;

Query OK, 0 rows affected (0.04 sec)


mysql> desc sort;

+--------+-------------+------+-----+---------+-------+

| Field  | Type        | Null | Key | Default | Extra |

+--------+-------------+------+-----+---------+-------+

| sid    | int(11)     | NO   | PRI | NULL    |       |

| sname  | varchar(50) | YES  |     | NULL    |       |

| sprice | double      | YES  |     | NULL    |       |

| sdesc  | varchar(50) | YES  |     | NULL    |       |

+--------+-------------+------+-----+---------+-------+

4 rows in set (0.01 sec)


mysql> exit;

Bye

bogon:~ tinghou$ mysql -u root -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 304

Server version: 5.6.12 MySQL Community Server (GPL)


Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> create database mybase;

Query OK, 1 row affected (0.01 sec)


mysql> use mybase;

Database changed

mysql> create table sort(

    -> sid int primary key,

    -> sname varchar(50),

    -> sprice double,

    -> sdesc varchar(50)

    -> );

Query OK, 0 rows affected (0.02 sec)


mysql> desc sort;

+--------+-------------+------+-----+---------+-------+

| Field  | Type        | Null | Key | Default | Extra |

+--------+-------------+------+-----+---------+-------+

| sid    | int(11)     | NO   | PRI | NULL    |       |

| sname  | varchar(50) | YES  |     | NULL    |       |

| sprice | double      | YES  |     | NULL    |       |

| sdesc  | varchar(50) | YES  |     | NULL    |       |

+--------+-------------+------+-----+---------+-------+

4 rows in set (0.01 sec)


mysql> insert into sort(sid,sname,sprice,sdesc)values(1,'zhangsan',60.5,'heihei);

    '> 

    '> insert into sort(sid,sname,sprice,sdesc) values(1,'zhangsan',60.5,'heihei);

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'zhangsan',60.5,'heihei)' at line 1

mysql> insert into sort(sid,sname,sprice,sdesc) values(1,'zhangsan',60.5,'heihei');

Query OK, 1 row affected (0.01 sec)


mysql>  insert into sort(sid,sname,sprice,sdesc) values(2,'zl',55.8,'hh');

Query OK, 1 row affected (0.01 sec)


mysql> select *from sort;

+-----+----------+--------+--------+

| sid | sname    | sprice | sdesc  |

+-----+----------+--------+--------+

|   1 | zhangsan |   60.5 | heihei |

|   2 | zl       |   55.8 | hh     |

+-----+----------+--------+--------+

2 rows in set (0.00 sec)


mysql> select *from sort;

+-----+----------+--------+--------+

| sid | sname    | sprice | sdesc  |

+-----+----------+--------+--------+

|   1 | zhangsan |   60.5 | heihei |

|   2 | zl       |   55.8 | hh     |

+-----+----------+--------+--------+

2 rows in set (0.00 sec)


mysql> create table users(

    -> username varchar(50),

    -> password varchar(50)

    -> );

Query OK, 0 rows affected (0.03 sec)


mysql> insert into users values('zs','12345'),('zl','123'),('ww','456');

Query OK, 3 rows affected (0.01 sec)

Records: 3  Duplicates: 0  Warnings: 0


mysql> select *from users;

+----------+----------+

| username | password |

+----------+----------+

| zs       | 12345    |

| zl       | 123      |

| ww       | 456      |

+----------+----------+

3 rows in set (0.00 sec)


mysql> drop table users;

Query OK, 0 rows affected (0.01 sec)


mysql> create table users(

    -> id int primary key auto_increment,

    -> username varchar(100),

    -> password varchar(100)

    -> );

Query OK, 0 rows affected (0.02 sec)


mysql> insert into users(username,password) values('zs','123'),('zl','456');

Query OK, 2 rows affected (0.00 sec)

Records: 2  Duplicates: 0  Warnings: 0


mysql> select *from users;

+----+----------+----------+

| id | username | password |

+----+----------+----------+

|  1 | zs       | 123      |

|  2 | zl       | 456      |

+----+----------+----------+

2 rows in set (0.00 sec)


mysql> 


你可能感兴趣的:(数据库,javaEE_javaWeb)