SQL comm -Part 1
SQL comm -Part 1
Informatics Practices
Class XI
SQL
SQL (pronounced SEQUEL for Simple English
Query Language) is a universal data access language
used to access and manipulate data stored in nearly all
the data bases.
According to ANSI (American National Standards
Institute), it is the standard language used to interact
with relational database management systems.
SQL Commands
SQL commands can be classified into the following:
• Data Definition Language (DDL): CREATE DATABASE, CREATE TABLE, ALTER
TABLE , DROP TABLE and DROP DATABASE commands.
• Data Manipulation Language (DML):
INSERT, UPDATE and DELETE.
• Transaction Control Language (TCL):
COMMIT,ROLLBACK,SAVEPOINT.
• Data Control Language (DCL): Grant , Revoke
Syntax:
mysql> create table tablename
( <col name> <data type>(width),
<col name> <data type>(width),
……………...
);
create table student
( roll int ,
name char (30) ,
fee decimal(7,2),
address varchar2(50),
age integer(2) ) ;
Syntax:
Alter table tablename
Add/Modify/Drop Column specifications;
Example:
(a) Alter Table student add addr char(50);
(b) Alter Table student
modify name char(50);
(c) Alter Table student drop age;
(d) Alter table student change roll admno int(5);
Note: While changing column name, do not forget to specify
datatype and width
Once the alterations are done, in order to see whether the changes were
applied or not, we need to the check the structure of the table which we
do using the DESC command.
mysql> desc student;
How has the above changes effected my records?? In order to check that
we see the set of records with the help of select
New column
Command.
added
Earlier status
of the table:
7. Delete : This command can be used to delete or remove rows
from a table or a database.
Syntax:
a) delete from tablename;
b) delete from tablename where condition;
Example:
(a) delete from student;
(b) delete from student
where roll>=2;
8. Drop Table : This command can be used to permanently
delete/ remove a table from the database.
Syntax:
Drop Table tablename;
Example:
mysql>drop table student;
9. Select database(): This command is used to know the database
currently in use.
mysql> select database();