欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

mysql中數(shù)據(jù)表基本操作的示例

這篇文章主要介紹MySQL中數(shù)據(jù)表基本操作的示例,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

專注于為中小企業(yè)提供網(wǎng)站建設(shè)、網(wǎng)站制作服務(wù),電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)寧德免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了千余家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。

案例:創(chuàng)建數(shù)據(jù)庫company,按照下面兩個表給出的表結(jié)構(gòu)在company數(shù)據(jù)庫中創(chuàng)建兩個數(shù)據(jù)表offices和employees,按照操作過程完成數(shù)據(jù)表的基本操作。

mysql中數(shù)據(jù)表基本操作的示例

操作過程如下:

(1):登錄MySQL。

mysql -h localhost -u root -p

打開windows命令行,輸入登錄用戶名和密碼:

C:\Users\Hudie>mysql -h localhost -u root -p
Enter password: ********Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 19Server version: 8.0.16 MySQL Community Server - GPL

Copyright (c) 2000, 2019, 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>_

登錄成功,可以輸入SQL語句進行操作。


(2):創(chuàng)建數(shù)據(jù)庫company。

create database company;
mysql> create database company;Query OK, 1 row affected (0.06 sec)

創(chuàng)建成功后,在company數(shù)據(jù)庫中創(chuàng)建數(shù)據(jù)表,必須先選擇該數(shù)據(jù)庫。SQL語句如下:

mysql> use company;Database changed

(3):創(chuàng)建表offices。

create table offices
mysql> create table offices    -> (
    -> officeCode int(10) not null unique,
    -> city varchar(50) not null,
    -> address varchar(50) not null,
    -> country varchar(50) not null,
    -> postalCode varchar(15) not null,
    -> primary key (officeCode)
    -> );Query OK, 0 rows affected (0.14 sec)mysql> show tables;+-------------------+| Tables_in_company |+-------------------+| offices           |+-------------------+1 row in set (0.00 sec)

(4):創(chuàng)建表enployees。

create table employees
mysql> create table employees    -> (
    -> employeeNumber int(11) not null primary key auto_increment,
    -> lastNamee varchar(50) not null,
    -> firstName varchar(50) not null,
    -> mobile varchar(25) not null,
    -> officeCode int (10) not null,
    -> jobTitle varchar(50) not null,
    -> birth datetime,
    -> noth varchar(25),
    -> sex varchar(5),
    -> constraint office_fk foreign key(officeCode) references offices(officeCode)
    -> );Query OK, 0 rows affected (0.14 sec)mysql> show tables;+-------------------+| Tables_in_company |+-------------------+| employees         || offices           |+-------------------+2 rows in set (0.01 sec)

創(chuàng)建成功,查看兩個表的結(jié)構(gòu):

mysql> desc offices;+------------+-------------+------+-----+---------+-------+| Field      | Type        | Null | Key | Default | Extra |+------------+-------------+------+-----+---------+-------+| officeCode | int(10)     | NO   | PRI | NULL    |       || city       | varchar(50) | NO   |     | NULL    |       || address    | varchar(50) | NO   |     | NULL    |       || country    | varchar(50) | NO   |     | NULL    |       || postalCode | varchar(15) | NO   |     | NULL    |       |+------------+-------------+------+-----+---------+-------+5 rows in set (0.06 sec)mysql> desc employees;+----------------+-------------+------+-----+---------+----------------+| Field          | Type        | Null | Key | Default | Extra          |+----------------+-------------+------+-----+---------+----------------+| employeeNumber | int(11)     | NO   | PRI | NULL    | auto_increment || lastNamee      | varchar(50) | NO   |     | NULL    |                || firstName      | varchar(50) | NO   |     | NULL    |                || mobile         | varchar(25) | NO   |     | NULL    |                || officeCode     | int(10)     | NO   | MUL | NULL    |                || jobTitle       | varchar(50) | NO   |     | NULL    |                || birth          | datetime    | YES  |     | NULL    |                || noth           | varchar(25) | YES  |     | NULL    |                || sex            | varchar(5)  | YES  |     | NULL    |                |+----------------+-------------+------+-----+---------+----------------+9 rows in set (0.01 sec)

(5):將表employees的mobile字段修改到officeCode字段后面。

alter table employees modify mobile varchar(25) after officeCode;
mysql> alter table employees modify mobile varchar(25) after officeCode;Query OK, 0 rows affected (0.18 sec)Records: 0  Duplicates: 0  Warnings: 0mysql> desc employees;+----------------+-------------+------+-----+---------+----------------+| Field          | Type        | Null | Key | Default | Extra          |+----------------+-------------+------+-----+---------+----------------+| employeeNumber | int(11)     | NO   | PRI | NULL    | auto_increment || lastNamee      | varchar(50) | NO   |     | NULL    |                || firstName      | varchar(50) | NO   |     | NULL    |                || officeCode     | int(10)     | NO   | MUL | NULL    |                || mobile         | varchar(25) | YES  |     | NULL    |                || jobTitle       | varchar(50) | NO   |     | NULL    |                || birth          | datetime    | YES  |     | NULL    |                || noth           | varchar(25) | YES  |     | NULL    |                || sex            | varchar(5)  | YES  |     | NULL    |                |+----------------+-------------+------+-----+---------+----------------+9 rows in set (0.01 sec)

(6):將表employees的birth字段改名為employee_birth。

alter table employees change birth employee_birth datetime;
mysql> alter table employees change birth employee_birth datetime;Query OK, 0 rows affected (0.03 sec)Records: 0  Duplicates: 0  Warnings: 0mysql> desc employees;+----------------+-------------+------+-----+---------+----------------+| Field          | Type        | Null | Key | Default | Extra          |+----------------+-------------+------+-----+---------+----------------+| employeeNumber | int(11)     | NO   | PRI | NULL    | auto_increment || lastNamee      | varchar(50) | NO   |     | NULL    |                || firstName      | varchar(50) | NO   |     | NULL    |                || officeCode     | int(10)     | NO   | MUL | NULL    |                || mobile         | varchar(25) | YES  |     | NULL    |                || jobTitle       | varchar(50) | NO   |     | NULL    |                || employee_birth | datetime    | YES  |     | NULL    |                || noth           | varchar(25) | YES  |     | NULL    |                || sex            | varchar(5)  | YES  |     | NULL    |                |+----------------+-------------+------+-----+---------+----------------+9 rows in set (0.00 sec)

(7):修改sex字段,設(shè)置數(shù)據(jù)類型為char(1),非空約束。

alter table employees modify sex char(1) not null;
mysql> alter table employees modify sex char(1) not null;Query OK, 0 rows affected (0.20 sec)Records: 0  Duplicates: 0  Warnings: 0mysql> desc employees;+----------------+-------------+------+-----+---------+----------------+| Field          | Type        | Null | Key | Default | Extra          |+----------------+-------------+------+-----+---------+----------------+| employeeNumber | int(11)     | NO   | PRI | NULL    | auto_increment || lastNamee      | varchar(50) | NO   |     | NULL    |                || firstName      | varchar(50) | NO   |     | NULL    |                || officeCode     | int(10)     | NO   | MUL | NULL    |                || mobile         | varchar(25) | YES  |     | NULL    |                || jobTitle       | varchar(50) | NO   |     | NULL    |                || employee_birth | datetime    | YES  |     | NULL    |                || noth           | varchar(25) | YES  |     | NULL    |                || sex            | char(1)     | NO   |     | NULL    |                |+----------------+-------------+------+-----+---------+----------------+9 rows in set (0.01 sec)

(8):刪除字段noth。

alter table employees drop noth;
mysql> alter table employees drop noth;Query OK, 0 rows affected (0.15 sec)Records: 0  Duplicates: 0  Warnings: 0mysql> desc employees;+----------------+-------------+------+-----+---------+----------------+| Field          | Type        | Null | Key | Default | Extra          |+----------------+-------------+------+-----+---------+----------------+| employeeNumber | int(11)     | NO   | PRI | NULL    | auto_increment || lastNamee      | varchar(50) | NO   |     | NULL    |                || firstName      | varchar(50) | NO   |     | NULL    |                || officeCode     | int(10)     | NO   | MUL | NULL    |                || mobile         | varchar(25) | YES  |     | NULL    |                || jobTitle       | varchar(50) | NO   |     | NULL    |                || employee_birth | datetime    | YES  |     | NULL    |                || sex            | char(1)     | NO   |     | NULL    |                |+----------------+-------------+------+-----+---------+----------------+8 rows in set (0.01 sec)

(9):增加字段名favoriate_activity,數(shù)據(jù)類型為varchar(100)

alter table employees add favoriate_activity varchar(100);
mysql> alter table employees add favoriate_activity varchar(100);Query OK, 0 rows affected (0.09 sec)Records: 0  Duplicates: 0  Warnings: 0mysql> desc employees;+--------------------+--------------+------+-----+---------+----------------+| Field              | Type         | Null | Key | Default | Extra          |+--------------------+--------------+------+-----+---------+----------------+| employeeNumber     | int(11)      | NO   | PRI | NULL    | auto_increment || lastNamee          | varchar(50)  | NO   |     | NULL    |                || firstName          | varchar(50)  | NO   |     | NULL    |                || officeCode         | int(10)      | NO   | MUL | NULL    |                || mobile             | varchar(25)  | YES  |     | NULL    |                || jobTitle           | varchar(50)  | NO   |     | NULL    |                || employee_birth     | datetime     | YES  |     | NULL    |                || sex                | char(1)      | NO   |     | NULL    |                || favoriate_activity | varchar(100) | YES  |     | NULL    |                |+--------------------+--------------+------+-----+---------+----------------+9 rows in set (0.00 sec)

(10):刪除主表offices

①刪除表的外鍵約束:alter table employees drop foreign key office_fk;
②刪除表offices:drop table offices;

mysql> alter table employees drop foreign key office_fk;Query OK, 0 rows affected (0.03 sec)Records: 0  Duplicates: 0  Warnings: 0mysql> drop table offices;Query OK, 0 rows affected (0.03 sec)mysql> show tables;+-------------------+| Tables_in_company |+-------------------+| employees         |+-------------------+1 row in set (0.06 sec)

(11):修改表employees存儲引擎為MyISAM。

alter table employees ENGINE=MyISAM;
mysql> alter table employees ENGINE=MyISAM;Query OK, 0 rows affected (0.17 sec)Records: 0  Duplicates: 0  Warnings: 0mysql> show create table employees \G*************************** 1. row ***************************
       Table: employeesCreate Table: CREATE TABLE `employees` (
  `employeeNumber` int(11) NOT NULL AUTO_INCREMENT,
  `lastNamee` varchar(50) NOT NULL,
  `firstName` varchar(50) NOT NULL,
  `officeCode` int(10) NOT NULL,
  `mobile` varchar(25) DEFAULT NULL,
  `jobTitle` varchar(50) NOT NULL,
  `employee_birth` datetime DEFAULT NULL,
  `sex` char(1) NOT NULL,
  `favoriate_activity` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`employeeNumber`),
  KEY `office_fk` (`officeCode`)) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci1 row in set (0.00 sec)

(12)將表employees名稱修改為employees_info。

alter table employees rename employees_info;
mysql> alter table employees rename employees_info;Query OK, 0 rows affected (0.07 sec)mysql> show tables;+-------------------+| Tables_in_company |+-------------------+| employees_info    |+-------------------+1 row in set (0.00 sec)

以上是“mysql中數(shù)據(jù)表基本操作的示例”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

本文題目:mysql中數(shù)據(jù)表基本操作的示例
文章源于:http://aaarwkj.com/article26/pesgcg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名網(wǎng)站設(shè)計公司、面包屑導航微信公眾號、網(wǎng)站策劃、網(wǎng)站導航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計公司
国产老熟女高潮一区二区| 国产女人和拘做受视频| 亚洲国产第一尤物视频| 亚洲精品中文字幕乱码三区91| 亚洲第一国产综合自拍| 日韩精品一区二区视频在线| 亚洲欧美成人免费视频| 日韩在线视频网站不卡| 蜜桃成人一区二区三区| 国产b片免费在线观看| 欧美精品亚洲精品日韩| 91在线视频国产网站| 日本成人午夜福利在线观看| 人妻少妇中文字幕一区| 国产农村熟妇av国语对白| 亚洲第一青青草原在线| 91女厕偷拍女厕偷拍| 国产不卡一区不卡二区| 热久久青草精品欧美一区| 新午夜福利片在线观看| 欧美精品一区二区三区黄片| 三级久久三级久久三级| 国内精品自产拍久久久久久久久91| 国产亚洲一区二区三区成人| 黄片无毛欧美在线观看| 99久久偷拍美女大白屁股| 国产精品超碰在线观看| 青青草免费在线视频视频| 国产一区二区欧美精品 | 日本在线免费成人高清| 青草草在线观看视频| 中文字幕乱码亚洲2019| 日本国产一区二区三区在线观看| 久久精品二区亚洲w码| 夫妻晚上同房太猛视频| 中文字幕人妻紧贴拍摄| 国产一区二区黄色录像| 日本精品在线亚洲国产欧美| 成人深夜免费观看视频| 亚洲巨人精品福利导航| 亚洲一区二区三区精品国产|