COMPUTER: SQL
SQL
(Structured Query Language)
SQL consists of a
1.data definition language,
2.data manipulation language, and
3.data control language
Data definition language
DDL: A data definition language or data description language (DDL) is a syntax similar to a computer programming language for defining data structures, especially database schemas.
CREATE statement
The CREATE command is used to establish a new database, table, index, or stored procedure.
CREATE TABLE [table name] ( [column definitions] ) [table parameters]
An example statement to create a table named employees with a few columns is:
CREATE TABLE employees (
id INTEGER PRIMARY KEY,
first_name VARCHAR(50) not null,
last_name VARCHAR(75) not null,
fname VARCHAR(50) not null,
dateofbirth DATE not null
);
DROP statement
The DROP statement destroys an existing database, table, index, or view.
DROP objecttype objectname.
For example, the command to drop a table named employees is:
DROP TABLE employees;
ALTER statement
The ALTER statement modifies an existing database object.
ALTER objecttype objectname parameters.
For example, the command to add (then remove) a column named bubbles for an existing table named sink is:
ALTER TABLE sink ADD bubbles INTEGER;
ALTER TABLE sink DROP COLUMN bubbles;
RENAME statement
The RENAME statement is used to rename a database table.
RENAME TABLE old_name TO new_name;
TRUNCATE statement
The TRUNCATE statement is used to delete all data from a table. It's much faster than DELETE.
TRUNCATE TABLE table_name;
Data manipulation language
A data manipulation language (DML) is a family of syntax elements similar to a computer programming language used for selecting, inserting, deleting and updating data in a database. Performing read-only queries of data is sometimes also considered a component of DML.
- SELECT ... FROM ... WHERE ...
- INSERT INTO ... VALUES ...
- UPDATE ... SET ... WHERE ...
- DELETE FROM ... WHERE ...
SELECT Statement
The SELECT statement is used to select data from a database. The data returned is stored in a result table, called the result-set.
SELECT Syntax
SELECT column1, column2, ...FROM table_name;
(Here, column1, column2, ... are the field names of the table you want to select data from.)
If you want to select all the fields available in the table, use the following syntax:
SELECT * FROM table_name;
SELECT DISTINCT Statement
The SELECT DISTINCT statement is used to return only distinct (different) values.
Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.
The SELECT DISTINCT statement is used to return only distinct (different) values.
SELECT DISTINCT Syntax
SELECT DISTINCT column1, column2, ...FROM table_name;
The SQL WHERE Clause
The WHERE clause is used to filter records.
The WHERE clause is used to extract only those records that fulfill a specified condition.
WHERE Syntax
SELECT column1, column2, ...FROM table_nameWHERE condition;
Data control language
A data control language (DCL) is a syntax similar to a computer programming language used to control access to data stored in a database (Authorization). In particular, it is a component of Structured Query Language (SQL).
Examples of DCL commands include:
- GRANT to allow specified users to perform specified tasks.
- REVOKE to cancel previously granted or denied permissions
QUESTION ANSWER
- SQL stands for- Structured Query Language
- RDBMS stands for- Relational Database Management System.
- A table is a collection of- related data entries and it consists of columns and rows.
Comments
Post a Comment