SQL basics 1: SQL Basics
1. What is SQL?
- SQL is a structured query language.
- SQL enables us to access databases
- SQL is an ANSI standard computer language.
Ii. What can SQL do?
- SQL queries for Databases
- SQL can retrieve data from the database
- SQL inserts new records into the database
- SQL updates database data
- SQL can delete records from the database
- SQL allows you to create a new database.
- SQL allows you to create a new table in the database.
- SQL allows you to create stored procedures in a database.
- SQL allows you to create a view in a database
- SQL allows you to set permissions for tables, stored procedures, and views.
Iii. SQL syntax
1. database tables
A database usually contains one or more tables. Each table is identified by a name (for example, "customer" or "order "). A table contains records (rows) with data ). The following example shows a table named "Persons:
Id |
LastName |
FirstName |
Address |
City |
1 |
Adams |
John |
Oxford Street |
London |
2 |
Bush |
George |
Th Avenue |
New York |
3 |
Carter |
Thomas |
Changan Street |
Beijing |
The table above contains three records (each corresponding to one person) and five columns (Id, last name, name, address, and city ).
2. SQL statements
Most of the work you need to execute on the database is completed by SQL statements.
The following statement selects the data in the LastName column from the table:
SELECT LastName FROM Persons
The result set is similar to the following:
LastName |
Adams |
Bush |
Carter |
** Important: SQL is case insensitive !!
SQL DML and DDL:
SQL can be divided into two parts: data operation language (DML) and Data Definition Language (DDL ).
SQL (Structured Query Language) is the syntax used to execute queries. However, the SQL language also contains the syntax used to update, insert, and delete records.
The query and update commands constitute the DML part of SQL:
SELECT-Retrieve data from a database table
- UPDATE-Update data in the database table
- DELETE-Delete data from a database table
- INSERT-Insert data to a database table
The Data Definition Language (DDL) Section of SQL enables us to create or Delete tables. We can also define indexes (KEYS), define links between tables, and apply constraints between tables.
The most important DDL statements in SQL:
- CREATE DATABASE-Create a new database
- ALTER DATABASE-Modify a database
- CREATE TABLE-Create a new table
- ALTER TABLE-Change the database table
- DROP TABLE-Delete a table
- CREATE INDEX-Create an index (search key)
- DROP INDEX-Delete An index