您的位置:首页 > 数据库

SQL进阶---第一单元(第一到第三课)、Manipulation

2017-10-08 18:36 513 查看
SQL进阶---第一单元、Manipulation
第一课、Introduction
MANIPULATIONIntroduction

Let's begin by entering a SQLcommand. In the code editor type
SELECT *FROM celebs;
You will run all of your SQLcommands in this course by pressing the Run button at the bottom of the codeeditor.
Instruction
select * from celebs;
QueryResults

id
name
age
1
Justin Bieber
22
2
Beyonce Knowles
33
3
Jeremy Lin
26
4
Taylor Swift
26
DatabaseSchema

Celebs           4 rows
id
INTEGER
name
TEXT
age
INTEGER
 
 
第二课、RelationalDatabases
MANIPULATION  Statements

SELECT * FROM celebs;

Nice work. In one line of code, you returned information from arelational database. We'll take a look at what this code means soon, for nowlet's focus on what relational databases are and how
they are organized.

1. A relational database is a database thatorganizesinformation into one or more tables. Here the relational
database contains onetable. 

2. A table is a collection of data organized intorows and columns. Tables are sometimes referred to as relations. Here the table is 
celebs


3. A column is a set of data values of aparticular type. Here 
id
name
,
and 
age
 are each columns. 

4. A row is a single record in a table.The first row in the celebstable has:

·       An id of 1
·       A name of Justin Bieber
All data stored in a relational database is of a certain data type. Someof the most common data types are:
1. Integer, a positive or negat
c21d
ive whole number 

2. Text, a text string 

3. Date, the date formatted as YYYY-MM-DD for the year, month, andday 

4. Real, a decimal value

 
第三课、CREATE TABLE
 

[b]MANIPULATION  Statements[/b]

CREATETABLE table_name (

        column_1 data_type,

        column_2 data_type,

        column_3 data_type

        );

The above code is a SQL statement. A statement is text that thedatabase recognizes as avalid command. Statements always end in a semi-colon 
;
.

Let's break down the components of a statement:

1.     
CREATE TABLE
 is a clause.
Clauses perform specific tasks in SQL. By convention, clausesare written in
capitalletters. Clauses can also be referred to ascommands.
2.     
table_name
 refers to the name of the table that thecommand
is applied to.
3.     
(column_1 data_type, column_2 data_type, column_3data_type)
 is
a parameter. A parameter is a list of columns, data types, or values thatare passed to a clause as an argument. Here, the parameter isa
list of column names andthe associated data type.
The structure of SQL statements vary. The number of lines useddo not matter. A statement can be written all on one line, or split up acrossmultiple lines if it makes it easier to read. In this course, you will becomefamiliar with
the structure of common statements.

Instructions
1.Now that you have a goodunderstanding of SQL syntax, let's create a new table.In the code editor type:
CREATETABLE celebs (
        idINTEGER,
        nameTEXT,
        ageINTEGER
        );
We will learn how to view this table in the next exercise after we haveadded some data to it.
CREATE TABLE celebs
         (
                  idINTEGER,
              name TEXT,
              age INTEGER
         );
Run a query to see results.

Database Schema

Celebs        0 rows
id
INTEGER
name
TEXT
age
INTEGER
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐