SQL进阶---第一单元(第四到第六课)、Manipulation
2017-10-09 21:26
309 查看
[align=center]SQL进阶---第一单元、Manipulation[/align]
第四课、MANIPULATION Create
MANIPULATION Create
This
creates a new tablein the database named
You can use the
anytime you want tocreate a new table from scratch.
1.
SQL you want to create a new table.
2.
the name of the table.
3.
a list of parameters definingeach column in the table and its data type.
the first column in the table. It stores values of data type
the second column in the table. It stores values of data type
the third column in the table. It stores values
1e2bf
of data type
Instructions
1.Add
a row to the table. In thecode editor type
INSERTINTO
celebs(id, name, age)
VALUES
(1,'Justin
Bieber',21);
INSERT INTOcelebs(id,name,age)
VALUES(1,'justin Bieber',21);
Run a query to
see results.
2.To
view the row you justcreated, under the INSERTstatementtype
SELECT *
FROM
celebs;
第五课、Insert
MANIPULATION Insert
This
inserts new rows intoa table. You can use the
when you want to addnew records.
1.
row or rows.
2.
the name of the table the rowis added to.
3.
a parameter identifying thecolumns that data will be inserted into.
4.
a clause that indicates the data being inserted.
a parameter identifying the values being inserted.
an integer that will be inserted into the
text that will be inserted into the
an integer that will be inserted into the
Instructions
1.Add
three more celebs to thetable. In the code editor type:
INSERTINTO
celebs(id, name, age)
VALUES
(2,'Beyonce
Knowles',33);
INSERTINTO
celebs(id, name, age)
VALUES
(3,'Jeremy
Lin',26);
INSERTINTO
celebs(id, name, age)
VALUES
(4,'Taylor
Swift',26);
2.Let's
take a closer look at SELECT.
Under the INSERTstatements
type
SELECT name
FROM
celebs;
INSERT INTO celebs (id, name, age)
VALUES (2, 'Beyonce Knowles', 33);
INSERT INTO celebs (id, name, age)
VALUES (3, 'Jeremy Lin', 26);
INSERT INTO celebs (id, name, age)
VALUES (4, 'Taylor Swift', 26);
SELECT name FROM celebs;
第六课、Select
MANIPULATION
Select
are used to fetchdata from a database. Here,
all data in the
of the
1.
a clause that indicatesthat the statement is a query. You will use
time you query data from a database.
2.
the column to query data from.
3.
the name of the table to query data from. In thisstatement, data is queried from the
You can also query data fromall columns in a table with
a special wildcardcharacter that we have been using. It allows you to select every column in atable without having to name each one individually.Here, the result set
containsevery column in the
always return anew table called the resultset.
Instructions
1.Now
that you know how to addrows to the table, let's edit a row. In the code editor type
UPDATE celebs
SET
age = 22WHERE
id = 1;
SELECT *
FROM
celebs;
UPDATE celebs SET age = 22
WHEREid =1;
SELECT * FROM celebs;
第四课、MANIPULATION Create
MANIPULATION Create
CREATE TABLE celebs (
id INTEGER,
name TEXT,
age INTEGER);
This
CREATEstatement
creates a new tablein the database named
celebs.
You can use the
CREATEstatement
anytime you want tocreate a new table from scratch.
1.
CREATE TABLEis a clause that tells
SQL you want to create a new table.
2.
celebsis
the name of the table.
3.
(id INTEGER,name TEXT, age INTEGER)is
a list of parameters definingeach column in the table and its data type.
idis
the first column in the table. It stores values of data type
INTEGER
nameis
the second column in the table. It stores values of data type
TEXT
ageis
the third column in the table. It stores values
1e2bf
of data type
INTEGER
Instructions
1.Add
a row to the table. In thecode editor type
INSERTINTO
celebs(id, name, age)
VALUES
(1,'Justin
Bieber',21);
INSERT INTOcelebs(id,name,age)
VALUES(1,'justin Bieber',21);
Run a query to
see results.
Database Schema
Celebs 1 rows | |
Id | INTEGER |
Name | TEXT |
Age | INTEGER |
view the row you justcreated, under the INSERTstatementtype
SELECT *
FROM
celebs;
Query Results
id | name | age |
1 | justin Bieber | 21 |
第五课、Insert
MANIPULATION Insert
INSERT INTO celebs (id, name, age) VALUES (1, 'Justin Bieber', 21);
This
INSERTstatement
inserts new rows intoa table. You can use the
INSERTstatement
when you want to addnew records.
1.
INSERT INTOis a clause that adds thespecified
row or rows.
2.
celebsis
the name of the table the rowis added to.
3.
(id, name,age)is
a parameter identifying thecolumns that data will be inserted into.
4.
VALUESis
a clause that indicates the data being inserted.
(1, 'Justin Bieber', 21)is
a parameter identifying the values being inserted.
1is
an integer that will be inserted into the
idcolumn
'Justin Bieber'is
text that will be inserted into the
namecolumn
21is
an integer that will be inserted into the
agecolumn
Instructions
1.Add
three more celebs to thetable. In the code editor type:
INSERTINTO
celebs(id, name, age)
VALUES
(2,'Beyonce
Knowles',33);
INSERTINTO
celebs(id, name, age)
VALUES
(3,'Jeremy
Lin',26);
INSERTINTO
celebs(id, name, age)
VALUES
(4,'Taylor
Swift',26);
2.Let's
take a closer look at SELECT.
Under the INSERTstatements
type
SELECT name
FROM
celebs;
INSERT INTO celebs (id, name, age)
VALUES (2, 'Beyonce Knowles', 33);
INSERT INTO celebs (id, name, age)
VALUES (3, 'Jeremy Lin', 26);
INSERT INTO celebs (id, name, age)
VALUES (4, 'Taylor Swift', 26);
SELECT name FROM celebs;
Query Results
name |
Justin Bieber |
Beyonce Knowles |
Jeremy Lin |
Taylor Swift |
Database Schema
Celebs 4 rows | |
Id | INTEGER |
Name | TEXT |
Age | INTEGER |
第六课、Select
MANIPULATION
Select
SELECT name FROM celebs;
SELECTstatements
are used to fetchdata from a database. Here,
SELECTreturns
all data in the
namecolumn
of the
celebstable.
1.
SELECTis
a clause that indicatesthat the statement is a query. You will use
SELECTevery
time you query data from a database.
2.
namespecifies
the column to query data from.
3.
FROM celebsspecifies
the name of the table to query data from. In thisstatement, data is queried from the
celebstable.
You can also query data fromall columns in a table with
SELECT.
SELECT * FROM celebs;
*is
a special wildcardcharacter that we have been using. It allows you to select every column in atable without having to name each one individually.Here, the result set
containsevery column in the
celebstable.
SELECTstatements
always return anew table called the resultset.
Instructions
1.Now
that you know how to addrows to the table, let's edit a row. In the code editor type
UPDATE celebs
SET
age = 22WHERE
id = 1;
SELECT *
FROM
celebs;
UPDATE celebs SET age = 22
WHEREid =1;
SELECT * FROM celebs;
Query Results
id | name | age |
1 | Justin Bieber | 22 |
2 | Beyonce Knowles | 33 |
3 | Jeremy Lin | 26 |
4 | Taylor Swift | 26 |
Database Schema
Celebs 4 rows | |
Id | INTEGER |
Name | TEXT |
Age | INTEGER |
相关文章推荐
- SQL进阶---第一单元(第一到第三课)、Manipulation
- SQL进阶---第一单元(第七到第十课)、Manipulation
- SQL进阶---第二单元(第一到第四课)、Queries
- Mybatis步步进阶(三)——1:N关系配置 && 动态SQL拼接
- T-SQL查询进阶
- sql语句进阶教程(学习sql这一篇就够了)
- SQL Server 扩展事件(Extented Events)从入门到进阶(1)——从SQL Trace到Extented Events
- SQL进阶提升(平时小积累)-学习sql server2005 step by step(十)
- 笨办法学 Python · 续 第六部分:SQL 和对象关系映射
- T-SQL进阶
- 【转】T-SQL查询进阶--深入浅出视图
- 自学PL/SQL 第四讲Writing Control Structures
- SQL进阶之CASE...WHEN
- 三星电子2017年研发投入位列全球第四 华为第六
- Oracle基础(五)pl/sql进阶(分页过程)
- mysql进阶(十九)SQL语句如何精准查找某一时间段的数据
- SQL 进阶学习之六
- sql 入门经典(第五版) Ryan Stephens 学习笔记 第四部分:建立复杂的数据库查询/
- 数据库技能实战进阶之常用结构化sql语句(上)
- java.sql.SQLException: Can not issue data manipulation statements with executeQuery()