Websites;
----+--------------+---------------------------+-------+---------+
| id | name | url | alexa | country || 5 | Facebook | https://www.facebook.com/ | 3 | USA |
+----+--------------+---------------------------+-------+---------+
我要在数据库中创建上面的表,首先是先写一个建表语句。
A=> create table Websites(id int ,name char(20),url char(50),alexa int,country char(10));
CREATE TABLE
A=> select * from Websites;
id | name | url | alexa | country
----+------+-----+-------+---------
(0 rows)
接着往表里面插入数据:
A=> insert into Websites values('1','Google','https://www.google.com/','1','country');
INSERT 0 1
A=> select * from Websites;
id | name | url | alexa | country
----+----------------------+----------------------------------------------------+-------+------------
1 | Google | https://www.google.com/ | 1 | country
(1 row)
接着往里面插剩下的四条数据
A=> insert into Websites values('2','TaoBao','https://www.taobao.com/','13','CN');
INSERT 0 1
A=> select * from Websites;
id | name | url | alexa | country
----+----------------------+----------------------------------------------------+-------+------------
1 | Google | https://www.google.com/ | 1 | country
2 | TaoBao | https://www.taobao.com/ | 13 | CN
(2 rows)
小编写到这里突然意识到上面的第一条记录的country值输入错误了(真心不是故意的,无意的),所以可以用update语句来更新哦。
A=> update Websites set country='USA' where id='1';
UPDATE 1
A=> select * from Websites;
id | name | url | alexa | country
----+----------------------+----------------------------------------------------+-------+------------
2 | TaoBao | https://www.taobao.com/ | 13 | CN
1 | Google | https://www.google.com/ | 1 | USA
(2 rows)
但是从上表可以看出,记录1和记录2 的位置颠倒了啊,我也是刚开始真刀实枪的操作数据库,不太懂啊。我可以理解为,这句话就是不会用语言说出来。。。
表中的记录是按时间顺序排列的么。。自己理会吧。
继续插入剩下的三条记录,可以忽略。。
A=> insert into Websites values('3','CaiNiao','http://www.runoob.com/','4689','CN');
INSERT 0 1
A=> insert into Websites values('4','WeiBo','http://www.weibo.com/','20','CN');
INSERT 0 1
A=> insert into Websites values('5','FaceBook','http://www.facebook.com/','3','USA');
INSERT 0 1
A=> select * from Websites;
id | name | url | alexa | country
----+----------------------+----------------------------------------------------+-------+------------
2 | TaoBao | https://www.taobao.com/ | 13 | CN
1 | Google | https://www.google.com/ | 1 | USA
3 | CaiNiao | http://www.runoob.com/ | 4689 | CN
4 | WeiBo | http://www.weibo.com/ | 20 | CN
5 | FaceBook | http://www.facebook.com/ | 3 | USA
(5 rows)