Introduction to SQL I
Introduction to SQL I
SQL is a domain-specific programming language designed for managing data in a relational database management system(RDBMS), and is used by a huge number of apps and organizations. For more information, please click the following link: SQL_wiki
Nowadays, people who work as data scienctist and analyst, software developer and even web designer require to use SQL as a tool for sharing and managing data in RDBMS. This post aims to record my self-learning experience and share with people who would like to learnig some basic technics in SQL. So, Let’s get started.
- About SQL
SQL are compoesd of three parts
Data Definition Language (DDL)
Data Manipulation Language (DML)
Data Control Language (DCL)
Today, I will introduce the first part, DDL.
- About Tables
Before we go through the Syntax of SQL, we whould have fundemantal understading about the
Tables
.
Data direction | name | also known as |
---|---|---|
horizontal | Rows | Observations |
vertical | Columns | Variables |
Important Syntax in DDL
- remark: the syntax and function of SQL need to be all capitals. e.g. SELECT, FROM and DROP.
- remark2: put the semicolon (
;
) in the end of statement.
- Create Statement
- The create command is used to establish a new database, table, index, or stored procedure.
Syntax: CREATE DATABASE
database-name
Example: CREATE DATABASEexerciseDB
;
Syntax: CREATE TABLE
table-name
Example: CREATE TABLEexercise_table
;
- Delete Statement
- The DROP statement destroys an existing database, table, index, or view.
Syntax: DROP DATABASE
database-name
Example: DROP DATABASEexerciseDB
;
Syntax: DROP TABLE
table-name
Example: DROP TABLEexercise_table
;
- Alter Statement
- The ALTER statement modifies an existing database object.
Syntax: ALTER DATABASE
database-name
MODIFY NAME =new_db
;
Example: ALTER DATABASEexerciseDB
MODIFY NAME =exerciseDB_new
;
Syntax: ALTER TABLE
table-name
ADD COLUMNcol_type
;
Example: ALTER TABLEexercise_table
ADD COLUMNAge
;
Syntax: ALTER TABLE
table-name
ADD PRIMARY KEYcol_name
;
Example: ALTER TABLEexercise_table
ADD PRIMARY KEYAge
;