What is basic SELECT statement?

Image
SELECT Statement A SELECT statement retrieves data from the database. With SELECT statement PROJECTION, SELECTION and JOIN can be performed on database tables. As data in relational database is stored in TABLES. TABLE has ROW and COLUMN structure. With SELECT statement all rows and all columns can be retrieved, this is known as PROJECTION. But, if rows and columns are retrieved on the basis of some condition, it is known as SELECTION. And suppose if some information is needed and that is stored in two or more different tables but are related, use JOINS to retrieve it from two or more tables. In SQL, basic SELECT statements are as follows: SELECT  * FROM  [ table_name ] ; SELECT   [ column1 ] ,  [ column2 ] ,  [ column3 ] ,   .....   FROM   [ table_name ] ; SELECT and FROM are known as clauses.  SELECT clause allows to specify columns to be selected from the database table.  FROM clause allows to specify table name that has those column to be s

What are different SQL statements?

SQL Statements

Basically there are three types of SQL statements:

1. DDL  - Data Definition Language
2. DML - Data Manipulation Language
3. DCL  - Data Control Language 


1) Data Definition Language:

It is used to define the database structure. It includes following statements:

CREATE

Very basic is the create table statement, used to create a database table:

CREATE TABLE [table_name] (
[column1] datatype,
[column2] datatype,
.....
);

ALTER

ALTER statement is used to add, delete or modify database table columns.

ALTER TABLE [table_name]
ADD [column_name] datatype;

ALTER TABLE [table_name]
DROP COLUMN [column_name];

ALTER TABLE [table_name]
MODIFY COLUMN [column_name] datatype;


DROP

DROP statement is used to remove complete table definition with all data.

DROP TABLE [table_name];


2) Data Manipulation Language:

It is used to manipulate data in database. It includes following statements:

SELECT

Very basic SELECT statement is for selecting rows and columns from the database table.

SELECT [*/column_name1, column_name2, ....]
FROM [table_name]
WHERE [condition];

UPDATE

UPDATE statement is used to modify records stored in database table.

UPDATE [table_name]
SET [coumn_name1 = value1], [column_name2  =  value2], [.....]
WHERE [condition];

INSERT

INSERT statement is used to add new record/row in database table.

INSERT INTO [table_name] ([column_name1, coulmn_name2, .....])
VALUES ([value1, value2, .....]);

DELETE

DELETE statement is used to remove record/row from database table.

DELETE FROM [table_name]
WHERE [condition];

3) Data Control Language:

It is used to handle database privileges. Basic privileges that can be granted or revoked from user are SELECT, UPDATE, INSERT, DELETE etc. 

It includes following statements:

GRANT

GRANT statement is used to give various privileges to user on an particular table.

GRANT [privileges] ON [table_name] TO [user];

REVOKE

REVOKE statement is used to cancel the granted privilege to user on a particular table.

REVOKE [privileges] ON [table_name] FROM [user]; 



Comments

Popular posts from this blog

With the help of block diagram explain the architecture of a DBMS.

What do you mean by data model? What are different types of data models?

Define the terms: domain, tuple, attribute and relation