<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      mysql學(xué)習(xí)筆記2

      書接上回,重新進(jìn)入mysql,繼續(xù)學(xué)習(xí)新內(nèi)容。

      1.進(jìn)入mysql并新建數(shù)據(jù)庫

      sudo mysql -u root -p
      
      create database test_database;
      
      use test_database;
      
      select database();
      

      可以看到

      mysql> select database();
      +---------------+
      | database()    |
      +---------------+
      | test_database |
      +---------------+
      1 row in set (0.00 sec)
      

      2.表格

      新建
      mysql> create table users(
          -> id int auto_increment primary key,
          -> name varchar(100) not null,
          -> email varchar(100),
          -> age int);
      Query OK, 0 rows affected (0.03 sec)
      
      查看
      mysql> select * from users;
      Empty set (0.00 sec)
      

      select查詢關(guān)鍵字
      *,表示選擇表中的所有列
      from指定來源關(guān)鍵字,后面跟的名字

      給表users增加數(shù)據(jù)并查看
      mysql> insert into users(name,email,age) values 
          -> ('張三','zhangsan@example.com',20),
          -> ('Zhangsan','ZS@example.com',25);
      Query OK, 2 rows affected (0.01 sec)
      Records: 2  Duplicates: 0  Warnings: 0
      
      mysql> select * from users;
      +----+----------+----------------------+------+
      | id | name     | email                | age  |
      +----+----------+----------------------+------+
      |  1 | 張三     | zhangsan@example.com |   20 |
      |  2 | Zhangsan | ZS@example.com       |   25 |
      +----+----------+----------------------+------+
      2 rows in set (0.00 sec)
      

      可以看到兩條數(shù)據(jù)添加完成。

      繼續(xù)插入數(shù)據(jù)
      mysql> insert into users(name,email,age) values 
          -> ('李四','lisi@example.com',66);
      Query OK, 1 row affected (0.00 sec)
      mysql> select * from users;
      +----+----------+----------------------+------+
      | id | name     | email                | age  |
      +----+----------+----------------------+------+
      |  1 | 張三     | zhangsan@example.com |   20 |
      |  2 | Zhangsan | ZS@example.com       |   25 |
      |  3 | 李四     | lisi@example.com     |   66 |
      +----+----------+----------------------+------+
      3 rows in set (0.00 sec)
      
      更新表中的數(shù)據(jù)

      使用update+更新的表名+set+更改的元素名字=新數(shù)據(jù)+ where+需要更新的數(shù)據(jù)條件

      update users set age = 88 where name = '張三';
      Query OK, 1 row affected (0.00 sec)
      Rows matched: 1  Changed: 1  Warnings: 0
      mysql> select * from users;
      +----+----------+----------------------+------+
      | id | name     | email                | age  |
      +----+----------+----------------------+------+
      |  1 | 張三     | zhangsan@example.com |   88 |
      |  2 | Zhangsan | ZS@example.com       |   25 |
      |  3 | 李四     | lisi@example.com     |   66 |
      +----+----------+----------------------+------+
      3 rows in set (0.00 sec)
      

      注意:此處如果出現(xiàn)多條數(shù)據(jù)都符合需要更新的數(shù)據(jù)條件,那么所有符合條件的數(shù)據(jù)都會被更新。

      刪除一條數(shù)據(jù)
      mysql> delete from users where name = '張三';
      Query OK, 1 row affected (0.01 sec)
      
      mysql> select * from users;
      +----+----------+------------------+------+
      | id | name     | email            | age  |
      +----+----------+------------------+------+
      |  2 | Zhangsan | ZS@example.com   |   25 |
      |  3 | 李四     | lisi@example.com |   66 |
      +----+----------+------------------+------+
      2 rows in set (0.00 sec)
      

      delete操作也是按照where的條件進(jìn)行數(shù)據(jù)刪除,也會把所有符合條件的數(shù)據(jù)都刪掉。

      復(fù)制表格(方法一)
      先新建一個(gè)相同結(jié)構(gòu)的空表

      使用create table+新表+ like+舊表

      mysql> create table new_users like users;
      Query OK, 0 rows affected (0.03 sec)
      
      mysql> select * from new_users;
      Empty set (0.00 sec)
      
      再把舊表內(nèi)容插入新表

      insert into+表名+select * from 源

      mysql> insert into new_users select * from users;
      Query OK, 2 rows affected (0.00 sec)
      Records: 2  Duplicates: 0  Warnings: 0
      
      mysql> select * from new_users;
      +----+----------+------------------+------+
      | id | name     | email            | age  |
      +----+----------+------------------+------+
      |  2 | Zhangsan | ZS@example.com   |   25 |
      |  3 | 李四     | lisi@example.com |   66 |
      +----+----------+------------------+------+
      2 rows in set (0.00 sec)
      
      復(fù)制表格(方法二)

      使用create table+新表+as+select * from 源

      mysql> create table n_users as select * from users;
      Query OK, 2 rows affected (0.03 sec)
      Records: 2  Duplicates: 0  Warnings: 0
      
      mysql> select * from n_users;
      +----+----------+------------------+------+
      | id | name     | email            | age  |
      +----+----------+------------------+------+
      |  2 | Zhangsan | ZS@example.com   |   25 |
      |  3 | 李四     | lisi@example.com |   66 |
      +----+----------+------------------+------+
      2 rows in set (0.00 sec)
      
      方法比較

      方法二復(fù)制的表格沒有保留原表格中id列的自增屬性。
      所以在增加數(shù)據(jù)后,id列不會自動編號。

      mysql> insert into n_users(name,email,age) values('張三','zhangsan@example.com',22);
      Query OK, 1 row affected (0.01 sec)
      
      mysql> select * from n_users;
      +----+----------+----------------------+------+
      | id | name     | email                | age  |
      +----+----------+----------------------+------+
      |  2 | Zhangsan | ZS@example.com       |   25 |
      |  3 | 李四     | lisi@example.com     |   66 |
      |  0 | 張三     | zhangsan@example.com |   22 |
      +----+----------+----------------------+------+
      3 rows in set (0.00 sec)
      
      mysql> insert into n_users(name,email,age) values('王五','ww@example.com',23);
      Query OK, 1 row affected (0.00 sec)
      
      mysql> select * from n_users;
      +----+----------+----------------------+------+
      | id | name     | email                | age  |
      +----+----------+----------------------+------+
      |  2 | Zhangsan | ZS@example.com       |   25 |
      |  3 | 李四     | lisi@example.com     |   66 |
      |  0 | 張三     | zhangsan@example.com |   22 |
      |  0 | 王五     | ww@example.com       |   23 |
      +----+----------+----------------------+------+
      4 rows in set (0.00 sec)
      

      方法一是可以自增

      mysql> insert into new_users(name,email,age) values('王五','ww@example.com',23);
      
      Query OK, 1 row affected (0.00 sec)
      
      mysql> select * from new_users;
      +----+----------+------------------+------+
      | id | name     | email            | age  |
      +----+----------+------------------+------+
      |  2 | Zhangsan | ZS@example.com   |   25 |
      |  3 | 李四     | lisi@example.com |   66 |
      |  4 | 王五     | ww@example.com   |   23 |
      +----+----------+------------------+------+
      3 rows in set (0.00 sec)
      

      #######解決方法二的自增問題
      #######查看n_users表的結(jié)構(gòu)

      mysql> describe n_users;
      +-------+--------------+------+-----+---------+-------+
      | Field | Type         | Null | Key | Default | Extra |
      +-------+--------------+------+-----+---------+-------+
      | id    | int          | NO   |     | 0       |       |
      | name  | varchar(100) | NO   |     | NULL    |       |
      | email | varchar(100) | YES  |     | NULL    |       |
      | age   | int          | YES  |     | NULL    |       |
      +-------+--------------+------+-----+---------+-------+
      4 rows in set (0.00 sec)
      

      使用alter table++modify id int auto_increment primary key更改字段屬性
      MODIFY修改現(xiàn)有的列
      id修改的列的名稱
      int列的數(shù)據(jù)類型
      auto_increment自動遞增屬性
      primary key表的主鍵,唯一且不能為null,每個(gè)表只有1個(gè)主鍵。

      mysql> alter table n_users modify id int auto_increment primary key;
      Query OK, 2 rows affected (0.07 sec)
      Records: 2  Duplicates: 0  Warnings: 0
      

      #######再次查看表結(jié)構(gòu)

      mysql> describe n_users;
      +-------+--------------+------+-----+---------+----------------+
      | Field | Type         | Null | Key | Default | Extra          |
      +-------+--------------+------+-----+---------+----------------+
      | id    | int          | NO   | PRI | NULL    | auto_increment |
      | name  | varchar(100) | NO   |     | NULL    |                |
      | email | varchar(100) | YES  |     | NULL    |                |
      | age   | int          | YES  |     | NULL    |                |
      +-------+--------------+------+-----+---------+----------------+
      4 rows in set (0.01 sec)
      

      可以看到多了 PRIauto_increment屬性

      查看數(shù)據(jù)庫中的表
      mysql> show tables;
      +-------------------------+
      | Tables_in_test_database |
      +-------------------------+
      | n_users                 |
      | new_users               |
      | users                   |
      +-------------------------+
      3 rows in set (0.00 sec)
      
      刪除表

      使用drop table刪除表

      mysql> drop table n_users;
      Query OK, 0 rows affected (0.02 sec)
      
      mysql> show tables;
      +-------------------------+
      | Tables_in_test_database |
      +-------------------------+
      | new_users               |
      | users                   |
      +-------------------------+
      2 rows in set (0.00 sec)
      
      posted @ 2024-09-24 09:36  科里布  閱讀(18)  評論(0)    收藏  舉報(bào)
      主站蜘蛛池模板: 99中文字幕国产精品| 四虎影视库国产精品一区| 日本国产精品第一页久久| 国产高清精品在线一区二区| 国产亚洲精品一区二区不卡| 在线播放亚洲成人av| 久久中精品中文字幕入口| 国产不卡av一区二区| 亚洲国产成人综合精品| 亚洲国产女性内射第一区| 亚洲一区二区三区自拍天堂| 亚洲国产精品自在拍在线播放蜜臀 | 国产精品亚洲二区在线看| 亚洲偷自拍国综合| 水蜜桃视频在线观看免费18| 蜜芽久久人人超碰爱香蕉| 久久96热在精品国产高清| 精品亚洲国产成人av| 在线免费不卡视频| 熟妇人妻无码中文字幕老熟妇| 亚洲av一本二本三本| 男女一级国产片免费视频| 欧美午夜小视频| 亚洲精品免费一二三区| 国产99视频精品免费视频6| 亚洲国产成人无码电影| 精品国产免费人成网站| 中文字幕日韩精品有码| 呦系列视频一区二区三区| 韩国美女福利视频在线观看| 午夜精品久久久久久久2023| 色综合久久一区二区三区| 亚洲一区二区三区啪啪| 91久久亚洲综合精品成人| 黄色免费在线网址| 国产精品自在线拍国产手机版| 国产一区二区不卡视频在线| 无套内谢少妇一二三四| 贵港市| 亚洲综合一区二区精品导航| 成人午夜福利一区二区四区|