Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views2 pages

SQL Notes - I

Computer science

Uploaded by

pandeyyuvraj311
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)
4 views2 pages

SQL Notes - I

Computer science

Uploaded by

pandeyyuvraj311
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/ 2

SQL

SQL stands for Structured Query Language.

It is a standard language used for manipulating, storing, and retrieving data in database.

It is a standard language for Relational Database System.

SQL can be used for the following:

- It can execute queries against a database.

- It can be used to retrieve data from a database.

- It can also insert, delete, update records in a database.

- Using SQL one can create new databases as well as create new tables in a database.

- It can create views in a database.

- It can also set permissions on tables, procedures, and views.

Commands:

Create, Update, Delete, Drop, Insert, Select.

The above and many more commands can be classified into the following groups based on their nature:

Sr. No. Language Command Usage of the command Syntax


Database Creation: Create Database
Database_name;
Example: Create Database College;
Table Creation: Create Table
This command is used to create table_name (column1 datatype, column2
the database or its objects (like datatype….);
Create table, views etc.) Example: Create Table students (id
number, name varchar (50), Roll_no
number, marks number);
ALTER TABLE – ADD: ALTER
TABLE table_name ADD
(Columnname_1 datatype,
Columnname_2 datatype….);
ALTER TABLE – DROP: ALTER
TABLE table_name DROP COLUMN
column_name;
Using Alter command one can
Alter ALTER TABLE-MODIFY: ALTER
1. Modify an existing database
DDL (Data TABLE table_name MODIFY
object, such as a table.
Definition column_name column_type;
Language) ALTER TABLE – RENAME: ALTER
TABLE table_name RENAME TO
new_table_name;
ALTER TABLE table_name RENAME
COLUMN old_name TO new_name
Dropping Database: Drop Database
Drop command is used to Delete Database_name;
Drop an entire table, a view of a table Example: Drop Database College;
or other objects in the database. Dropping Table: Drop Table table_name;
Example: Drop table students;
Truncate command is used to
remove all records from a table, Truncate table table_name; Example:
Truncate
including all spaces allocated for Truncate table students
the records are removed
Only Values: INSERT INTO table_name
VALUES (value1, value2, value3…);
Example: INSERT INTO Student
VALUES (5,’HARSH’,’WEST
BENGAL’,19);
Column names and values both:
Insert command is used to insert INSERT INTO table_name (column1,
Insert data into a table column2, column3...) VALUES (value1,
value2, value3,..);
Example: INSERT INTO Student
(ROLL_NO, NAME, Age) VALUES
(‘5′,’PRATIK’,’19’);
This command is used to update UPDATE table_name SET column1 =
DML (Data existing data within a table. value1 WHERE condition;
2. Manipulation Update Example: UPDATE Student SET NAME
Language) = 'PRATIK' WHERE Age = 20;
Delete command is used to DELETE FROM table_name WHERE
delete records from a database condition;
Delete table. Example: DELETE FROM Student
WHERE NAME = 'Ram’;

This command gives users


-
Grant access privileges to the database.
DCL (Data
3. Control
Language) This command withdraws user’s
Revoke access privileges given by using -
the GRANT command.

Commit command is used to


Commit save all the transactions to the -
TCL database.
(Transaction
4. Control
Language) Rollback command is used to
undo transactions that have not
Roll back -
already been saved to the
database.

It is used to roll the transaction


back to a certain point without
Save Point -
rolling back the entire
transaction.

Query to fetch selected fields:


SELECT column1, column2 FROM
This command is used to retrieve table_name; Example: SELECT
DQL (Data data from the database. ROLL_NO, NAME, AGE FROM
Select
5. Query students;
Language) Query to fetch all fields:
SELECT * FROM table_name; Example:
Select * from student

*******************************

You might also like