數據庫

數據庫
1970表頭:
列:具備相同類型的數據的集合
行:每一行用來描述某我的或者物的具體信息 一條完整的數據字段
鍵:用來識別某個特定的人或者是物的屬性或方法 鍵的值在當前列中具備惟一性
值:行的具體信息 每一個值必須與該列的數據類型相同mysql

sql將數據類型分爲3類
數值類型 整數型{迷你整型 tinyint 使用一個字節存儲 表示的狀態最多爲256個
小整型smalint 使用兩個字節 65536
中整型 mediumint 3個字節
標準整型 int 4個字節*
大整形 bigint 8個字節}
小數型{ 浮點型 小數點浮動 精度有限 會丟失精度 float(x/總長度,y/小數部分長度) 整數部分長度x-y 單精度 佔4個字節 精度範圍 7位左右 double 雙精度 8個 15位
定點型 小數點固定精度固定 不會丟失精度}
字符串(——utf-8) char(4)4*3—定長 浪費資源
varchar 4*3+1 變長
text blob enum set
日期/時間
datatime yyyy-mm-dd hh:ii:ss
Data yyyy-mm-dd
Time: hh:ii:ss
Timestamp 時間戳 從1970開始的yyyy-mm-dd hh:ii:ss
Year sql

主鍵:primary key一張表中只能有一個主鍵 不能重複主鍵默認不能爲空
數據庫操做
查詢數據庫
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.07 sec)
建立數據庫
mysql> create database dear;
Query OK, 1 row affected (0.10 sec)數據庫

選中使用數據庫
mysql> use dear
Database changed
刪除數據庫
mysql> drop database dear;
Query OK, 0 rows affected (0.08 sec)spa

數據表操做
mysql> use dear;
Database changed
查看數據表-
mysql> show tables;
Empty set (0.00 sec)
建立數據表 (同時建立表頭)
create table my_info(
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(30) DEFAULT NULL,
`sex` varchar(2) DEFAULT NULL,
`birthday` date DEFAULT NULL,
PRIMARY KEY(`id`)
)ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
eg:
create table lcping(
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(30) DEFAULT NULL,
`sex` varchar(2) DEFAULT NULL,
`school` varchar(30) DEFAULT NULL,
`學號` varchar(30) DEFAULT NULL,
`成績` varchar(30) DEFAULT NULL,
PRIMARY KEY(`id`)
)ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;orm

 

查看數據表
mysql> show tables;
+----------------+
| Tables_in_dear |
+----------------+
| my_info |
+----------------+
1 row in set (0.00 sec)
查看錶結構
mysql> describe my_info;
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(30) | YES | | NULL | |
| sex | varchar(2) | YES | | NULL | |
| birthday | date | YES | | NULL | |
+----------+-------------+------+-----+---------+----------------+
4 rows in set (0.14 sec)
刪除數據表mysql> drop table my_info;
修改表名
insert into dear_mimi values(0,`李明`,`男`,`1998-5-5`);
insert into dear_mimi set id=3,name="aaa",sex="女",birthday="1337-5-5"
多條數據
mysql> insert into dear_mimi values(0,'李明','男','會計','150206229','65'),
-> (1,'李明','男','1994-5-6'),
-> (2,'李明','男','1994-5-6');utf-8

Query OK, 3 rows affected (0.17 sec)
Records: 3 Duplicates: 0 Warnings: 0
查詢數據
查詢全部數據 select * from 表名
(1,'林小明','男','會計','150206229','65'),
(2,'林大明','女','會計','150206230','30'),
(3,'林林明','男','會計','150206231','86'),
(4,'林是明','男','會計','150206232','52'),
(5,'林個明','女','會計','150206233','98'),
(6,'林額明','男','會計','150206234','69'),
(7,'李好明','女','會計','150206235','73'),
(8,'李就明','男','會計','150206236','65'),
(9,'李我明','男','會計','150206237','62'),
(10,'李玩明','男','會計','150206238','96'),
(11,'李明小','男','會計','150206229','65'),
(12,'李大額','女','會計','150206230','30'),
(13,'了明','男','會計','150206231','86'),
(14,'李額明','男','會計','150206232','52'),
(15,'李個他','女','會計','150206233','98'),
(16,'李額餓','男','會計','150206234','69'),
(17,'李好玩','女','會計','150206235','73'),
(18,'李就吧','男','會計','150206236','65'),
(19,'李我嗎','男','會計','150206237','62'),
(20,'李玩了','女','會計','150206238','96'),
(21,'李玩哦','男','會計','150206239','65');
(31,'林小明','男','計算機','150206229','65'),
(32,'林大明','女','計算機','150206230','30'),
(52,'林林明','男','計算機','150206231','86'),
(34,'林是明','男','數學','150206232','52'),
(35,'林個明','女','數學','150206233','98'),
(36,'林額明','男','計算機','150206234','69'),
(37,'白好明','女','計算機','150206235','73'),
(38,'白就明','男','數學','150206236','65'),
(39,'白我明','男','計算機','150206237','62'),
(40,'白玩明','男','數學','150206238','96'),
(41,'白明小','男','計算機','150206229','65'),
(42,'白大額','女','計算機','150206230','30'),
(43,'了明','男','計算機','150206231','86'),
(44,'白額明','男','數學','150206232','52'),
(45,'白個他','女','計算機','150206233','98'),
(46,'白額餓','男','計算機','150206234','69'),
(47,'白好玩','女','計算機','150206235','73'),
(48,'白就吧','男','計算機','150206236','65'),
(49,'白我嗎','男','語文','150206237','62'),
(50,'白玩了','女','計算機','150206238','96'),
(51,'白玩哦','男','計算機','150206239','65');資源

相關文章
相關標籤/搜索