91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

mysql sql語句學習(一)

發布時間:2020-08-08 17:27:56 來源:ITPUB博客 閱讀:132 作者:genweihua 欄目:MySQL數據庫

     為了學習數據庫,先熟悉一下sql語言,也就以mysql為例子開始學習了!

(參考書籍《深入淺出mysql 數據庫開發、優化、管理維護》)

   下邊是執行的sql語句,主要是建立表和修改表:

首先進入windows命令提示符下:

Microsoft Windows XP [版本 5.1.2600]
(C) 版權所有 1985-2001 Microsoft Corp.

C:\Documents and Settings\Administrator>mysql -uroot -proot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.41-community MySQL Community Server (GPL)

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

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.02 sec)

mysql> use test;
Database changed
mysql> create table emp(ename varchar(20) not null primary key,hirdate date,sal
decimal(10,2),deptno int(2));
Query OK, 0 rows affected (0.08 sec)

mysql> desc emp;
+---------+---------------+------+-----+---------+-------+
| Field   | Type          | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| ename   | varchar(20)   | NO   | PRI | NULL    |       |
| hirdate | date          | YES  |     | NULL    |       |
| sal     | decimal(10,2) | YES  |     | NULL    |       |
| deptno  | int(2)        | YES  |     | NULL    |       |
+---------+---------------+------+-----+---------+-------+
4 rows in set (0.02 sec)

mysql> show create table emp;
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------------------------------+
| Table | Create Table

                                                                 |
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------------------------------+
| emp   | CREATE TABLE `emp` (
  `ename` varchar(20) NOT NULL,
  `hirdate` date DEFAULT NULL,
  `sal` decimal(10,2) DEFAULT NULL,
  `deptno` int(2) DEFAULT NULL,
  PRIMARY KEY (`ename`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> alter table emp modify ename varchar(30);
Query OK, 0 rows affected (0.19 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc emp;
+---------+---------------+------+-----+---------+-------+
| Field   | Type          | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| ename   | varchar(30)   | NO   | PRI |         |       |
| hirdate | date          | YES  |     | NULL    |       |
| sal     | decimal(10,2) | YES  |     | NULL    |       |
| deptno  | int(2)        | YES  |     | NULL    |       |
+---------+---------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> alter table emp add column age int(3);
Query OK, 0 rows affected (0.19 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc emp;
+---------+---------------+------+-----+---------+-------+
| Field   | Type          | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| ename   | varchar(30)   | NO   | PRI |         |       |
| hirdate | date          | YES  |     | NULL    |       |
| sal     | decimal(10,2) | YES  |     | NULL    |       |
| deptno  | int(2)        | YES  |     | NULL    |       |
| age     | int(3)        | YES  |     | NULL    |       |
+---------+---------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> alter table emp change age agenum int(4);
Query OK, 0 rows affected (0.05 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc emp;
+---------+---------------+------+-----+---------+-------+
| Field   | Type          | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| ename   | varchar(30)   | NO   | PRI |         |       |
| hirdate | date          | YES  |     | NULL    |       |
| sal     | decimal(10,2) | YES  |     | NULL    |       |
| deptno  | int(2)        | YES  |     | NULL    |       |
| agenum  | int(4)        | YES  |     | NULL    |       |
+---------+---------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> alter table emp drop agenum;
Query OK, 0 rows affected (0.17 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc emp;
+---------+---------------+------+-----+---------+-------+
| Field   | Type          | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| ename   | varchar(30)   | NO   | PRI |         |       |
| hirdate | date          | YES  |     | NULL    |       |
| sal     | decimal(10,2) | YES  |     | NULL    |       |
| deptno  | int(2)        | YES  |     | NULL    |       |
+---------+---------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> alter table emp add column birth date after ename;
Query OK, 0 rows affected (0.16 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc emp;
+---------+---------------+------+-----+---------+-------+
| Field   | Type          | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| ename   | varchar(30)   | NO   | PRI |         |       |
| birth   | date          | YES  |     | NULL    |       |
| hirdate | date          | YES  |     | NULL    |       |
| sal     | decimal(10,2) | YES  |     | NULL    |       |
| deptno  | int(2)        | YES  |     | NULL    |       |
+---------+---------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> alter table emp modify sal first;
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 'first
' at line 1
mysql> alter table emp modify sal decimal(10,2) first;
Query OK, 0 rows affected (0.16 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc emp;
+---------+---------------+------+-----+---------+-------+
| Field   | Type          | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| sal     | decimal(10,2) | YES  |     | NULL    |       |
| ename   | varchar(30)   | NO   | PRI |         |       |
| birth   | date          | YES  |     | NULL    |       |
| hirdate | date          | YES  |     | NULL    |       |
| deptno  | int(2)        | YES  |     | NULL    |       |
+---------+---------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> alter table emp change ename name varchar(20) first;
Query OK, 0 rows affected (0.16 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc emp;
+---------+---------------+------+-----+---------+-------+
| Field   | Type          | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| name    | varchar(20)   | NO   | PRI |         |       |
| sal     | decimal(10,2) | YES  |     | NULL    |       |
| birth   | date          | YES  |     | NULL    |       |
| hirdate | date          | YES  |     | NULL    |       |
| deptno  | int(2)        | YES  |     | NULL    |       |
+---------+---------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> alter table emp change birth birthday date after hirdate;
Query OK, 0 rows affected (0.23 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc emp;
+----------+---------------+------+-----+---------+-------+
| Field    | Type          | Null | Key | Default | Extra |
+----------+---------------+------+-----+---------+-------+
| name     | varchar(20)   | NO   | PRI |         |       |
| sal      | decimal(10,2) | YES  |     | NULL    |       |
| hirdate  | date          | YES  |     | NULL    |       |
| birthday | date          | YES  |     | NULL    |       |
| deptno   | int(2)        | YES  |     | NULL    |       |
+----------+---------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> alter table emp rename emptable;
Query OK, 0 rows affected (0.22 sec)

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| emptable       |
+----------------+
1 row in set (0.00 sec)

mysql> drop table emptable;
Query OK, 0 rows affected (0.06 sec)

mysql> show tables;
Empty set (0.00 sec)

mysql> exit;
Bye

C:\Documents and Settings\Administrator>

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

龙游县| 河池市| 沙雅县| 科尔| 湘西| 舞钢市| 榆林市| 衡阳市| 辉县市| 邮箱| 噶尔县| 进贤县| 昂仁县| 三门县| 无棣县| 沛县| 潜江市| 罗江县| 通辽市| 崇明县| 韶关市| 德格县| 高陵县| 湘西| 阿瓦提县| 修武县| 威海市| 涟源市| 四平市| 嘉祥县| 桐庐县| 百色市| 汝州市| 平利县| 南澳县| 利川市| 峡江县| 沂南县| 巧家县| 浮山县| 泾川县|