如何用sql簡單創(chuàng)建一個四行四列表格
1.打開你的終端輸入/usr/local/MySQL/bin/mysql -u root –p
2.輸入你的密碼(mysql的密碼)
3.如果成功的話會看到這么一段~
Welcome tothe MySQL monitor.Commands end with ;or \g.
Your MySQL connection id is 22
Server version: 5.7.16 MySQLCommunity Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rightsreserved.
Oracle is a registered trademark of Oracle Corporation and/orits
affiliates. Other names may betrademarks of their respective
owners.
Type'help;' or '\h' for help. Type '\c' to clear the current input statement.
4.接著創(chuàng)建一個數(shù)據(jù)庫:create database message;(這貨是名字)
5.使用你當(dāng)前創(chuàng)建的數(shù)據(jù)庫:use message;(記得加分號了)
6.接著就是創(chuàng)建表格了:
create table person(
id int ,-------多個列用逗號隔開
name varchar(255),-------這里的255是(規(guī)定字符串長度菲盾,貌似省略不了啊)
city varchar(255),
address varchar(255)
);-----(至此,表格創(chuàng)建結(jié)束。)
7.向表格中添加數(shù)據(jù):
insert into person---向person表中插入數(shù)據(jù)
(id,name,city,address)---列的名字
values(20,’yp’,’qwer’,’asdf’);------所對應(yīng)的數(shù)據(jù)信轿,要一一對應(yīng)(字符串要用單引號括起來)
這樣就添加成功了
這時候輸入select *fromperson;
會出現(xiàn):
+------+------+---------+------+
| id| name | address | city |
+------+------+---------+------+
|20 | yp| qwer| asdf |
+------+------+---------+------+
8.然后再依次添加三行后輸入select *from person;
效果圖:
+------+------+---------+------+
| id| name | address | city |
+------+------+---------+------+
|20 | yp| qwer| asdf |
|18 | ww| zxcv| tyui |
|18 | zs| qazx| wsxc |
|23 | dg| ghjk| liop |
+------+------+---------+------+
恩大概就是這樣QAQ~