Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

SQL Commands

SQL, or Structured Query Language, is the standard language for managing and manipulating data in relational database systems (RDBMS) like MySQL and Oracle. It allows users to perform various operations such as creating tables, inserting data, and defining constraints, and is categorized into four main command types: DDL, DML, TCL, and DCL. The document also outlines basic SQL syntax and provides examples of common SQL commands.

Uploaded by

Kashif Belal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

SQL Commands

SQL, or Structured Query Language, is the standard language for managing and manipulating data in relational database systems (RDBMS) like MySQL and Oracle. It allows users to perform various operations such as creating tables, inserting data, and defining constraints, and is categorized into four main command types: DDL, DML, TCL, and DCL. The document also outlines basic SQL syntax and provides examples of common SQL commands.

Uploaded by

Kashif Belal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1

SQL Commands
What is SQL?
SQL is Structured Query Language, which is a computer language for storing, manipulating and
retrieving data stored in relational database.

SQL is the standard language for Relation Database System. All relational database management
systems like MySQL, MS Access, Oracle, Sybase, Informix, postgres and SQL Server use SQL
as standard database language.

Also, they are using different dialects, such as:

• MS SQL Server using T-SQL,

• Oracle using PL/SQL,

• MS Access version of SQL is called JET SQL (native format), etc

Why SQL?
• Allows users to access data in relational database management systems.

• Allows users to describe the data.

• Allows users to define the data in database and manipulate that data.

• Allows to embed within other languages using SQL modules, libraries & pre-compilers.

• Allows users to create and drop databases and tables.

• Allows users to create view, stored procedure, functions in a database.

• Allows users to set permissions on tables, procedures, and views

What is RDBMS?
RDBMS stands for Relational Database Management System. RDBMS is the basis for SQL and
for all modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft
Access.
2

A Relational database management system (RDBMS) is a database management system (DBMS)


that is based on the relational model as introduced by E. F. Codd.

What is table ?
The data in RDBMS is stored in database objects called tables. The table is a collection of related
data entries and it consists of columns and rows.

Remember, a table is the most common and simplest form of data storage in a relational database.

What is field?
Every table is broken up into smaller entities called fields. The fields in the CUSTOMERS table
consist of ID, NAME, AGE, ADDRESS and SALARY.

A field is a column in a table that is designed to maintain specific information about every record
in the table.

What is record or row?


A record, also called a row of data, is each individual entry that exists in a table. For example,
there are 7 records in the above CUSTOMERS table.

A record is a horizontal entity in a table.

What is column?
A column is a vertical entity in a table that contains all information associated with a specific
field in a table.

What is NULL value?


A NULL value in a table is a value in a field that appears to be blank which means A field with a
NULL value is a field with no value.

It is very important to understand that a NULL value is different than a zero value or a field that
contains spaces. A field with a NULL value is one that has been left blank during record creation.

SQL Constraints:
Constraints are the rules enforced on data columns on table. These are used to limit the type of
data that can go into a table. This ensures the accuracy and reliability of the data in the database.
3

Constraints could be column level or table level. Column level constraints are applied only to one
column where as table level constraints are applied to the whole table.

SQL Syntax:
SQL is followed by unique set of rules and guidelines called Syntax. This tutorial gives you a
quick start with SQL by listing all the basic SQL Syntax:

All the SQL statements start with any of the keywords like SELECT, INSERT, UPDATE,
DELETE, ALTER, DROP, CREATE, USE, SHOW and all the statements end with a semicolon
(;).

Important point to be noted is that SQL is case insensitive which means SELECT and select have
same meaning in SQL statements but MySQL make difference in table names. So if you are
working with MySQL then you need to give table names as they exist in the database.

COMMANDS:

SQL commands are instructions, coded into SQL statements, which are used to
communicate with the database to perform specific tasks, work, functions and queries with
data.
SQL commands can be used not only for searching the database but also to perform various
other functions like, for example, you can create tables, add data to tables, or modify data,
drop the table, set permissions for users. SQL commands are grouped into four major
categories depending on their functionality:
• Data Definition Language (DDL) - These SQL commands are used for creating,
modifying, and dropping the structure of database objects. The commands are
CREATE, ALTER, DROP, RENAME, and TRUNCATE.
• Data Manipulation Language (DML) - These SQL commands are used for
storing, retrieving, modifying, and deleting data.
These Data Manipulation Language commands
are: SELECT, INSERT, UPDATE, and DELETE.
• Transaction Control Language (TCL) - These SQL commands are used for
managing changes affecting the data. These commands are COMMIT,
ROLLBACK, and SAVEPOINT.
• Data Control Language (DCL) - These SQL commands are used for providing
security to database objects. These commands are GRANT and REVOKE.

1. SQL CREATE TABLE Statement:

CREATE TABLE table_name(


4

column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more columns )
);

2. SQL DROP TABLE Statement:


DROP TABLE table_name;

3. SQL ALTER TABLE Statement:


ALTER TABLE table_name {ADD|DROP|MODIFY} column_name {data_ype};

4. SQL ALTER TABLE Statement (Rename) :


ALTER TABLE table_name RENAME TO new_table_name;

5. SQL INSERT INTO Statement:


INSERT INTO table_name( column1, column2....columnN)
VALUES ( value1, value2....valueN);

6. SQL UPDATE Statement:


UPDATE table_name
SET column1 = value1, column2 = value2....columnN=valueN
[ WHERE CONDITION ];

7. SQL DELETE Statement:


DELETE FROM table_name
WHERE {CONDITION};

8. SQL SELECT Statement:


SELECT column1, column2....columnN
FROM table_name;

9. SQL DISTINCT Clause:


SELECT DISTINCT column1, column2....columnN
FROM table_name;
5

10. SQL WHERE Clause:


SELECT column1, column2....columnN
FROM table_name
WHERE CONDITION;

11. SQL AND/OR Clause:


SELECT column1, column2....columnN
FROM table_name
WHERE CONDITION-1 {AND|OR} CONDITION-2;

12. SQL IN Clause:


SELECT column1, column2....columnN
FROM table_name
WHERE column_name IN (val-1, val-2,...val-N);

13. SQL BETWEEN Clause:


SELECT column1, column2....columnN
FROM table_name
WHERE column_name BETWEEN val-1 AND val-2;

14. SQL Like Clause:


SELECT column1, column2....columnN
FROM table_name
WHERE column_name LIKE { PATTERN };

15. SQL ORDER BY Clause:


SELECT column1, column2....columnN
FROM table_name
WHERE CONDITION
ORDER BY column_name {ASC|DESC};

16. SQL GROUP BY Clause:


SELECT SUM(column_name)
FROM table_name
WHERE CONDITION
6

GROUP BY column_name;

17. SQL COUNT Clause:


SELECT COUNT(column_name)
FROM table_name
WHERE CONDITION;

You might also like