0% found this document useful (0 votes)
2 views

SQL comm -Part 1

SQL (Structured Query Language) is a universal data access language used to manipulate data in relational databases, with commands categorized into DDL, DML, TCL, and DCL. Key operations include creating databases and tables, inserting and modifying data, and querying data using commands like CREATE, INSERT, and SELECT. SQL commands are not case sensitive and various data types such as CHAR, VARCHAR, INT, and DECIMAL are supported.

Uploaded by

Anushka Rout
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SQL comm -Part 1

SQL (Structured Query Language) is a universal data access language used to manipulate data in relational databases, with commands categorized into DDL, DML, TCL, and DCL. Key operations include creating databases and tables, inserting and modifying data, and querying data using commands like CREATE, INSERT, and SELECT. SQL commands are not case sensitive and various data types such as CHAR, VARCHAR, INT, and DECIMAL are supported.

Uploaded by

Anushka Rout
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

INTRODUCTION TO SQL

(Structured Query Language)

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

NOTE: SQL commands are not case sensitive.


WORKING WITH SQL commands:
To work on MySQL, you need to create and open the
database first:

Create & Open Database:


1. mysql> CREATE DATABASE nameofdatabase;
Now the database with the given name will be created. If
the database already exist, then it gives an error.
In order to create tables inside a database, one has to open
the database first, which we do with USE command.
2. mysql> USE nameofdatabase;
Database would contain TABLES to
store the data in the form of rows and
columns.
Before creating tables and storing data
into it, we need to know :
What all kind of data SQL is able to
handle???
SQL Data Types:
Data Type Description Example
A fixed-length string between 1 and 255
CHAR(size) Values must be enclosed in single quotes or double quotes.
”Maths” ,
‘A-21 , Anand Vihar’
A variable-length string between 1 and 255 characters in ‘Computer’
VARCHAR(size)
length; Values must be enclosed in single quotes or double quotes ‘Me and u’

It can represent number with or without the decimal part.


17.3
p indicates the total number of digits including the integer and t
DECIMAL(p,s) /
FLOAT the decimal part. s represents maximum number of digits to the
right of the decimal point
It is used for storing integer values
INT/BIGINT 345
DATE It represents the date including day, month and year in the 2009-07-02
format yyyy-dd-mm
3. Create table : This command can be used to
define or create a table structure or schema.

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) ) ;

roll name fee address age


4. Describe : This command can be see the structure of
the table.
Synatx:
Describe tablename;
OR
Desc tablename;
Example:
mysql> desc student;
5. Insert into : This command can be used to
insert a row in a table.
Syntax:
a) insert into tablename values (values separated by
commas ) ;
b) insert into tablename (list of specific col) values
(values of sp col separated by commas ) ;
c) Inserting NULL values into records.
E.g.
(1) insert into student values (1, ‘Ajay’, 11998.50, ‘ND’,14);
(2) insert into student(name, age) values (‘Sunil’, 15);
(3) insert into student values( 12, ‘Tarun’, NULL, ‘Jaipur’,12);
roll name fee address age
1 Ajay 11998.50 ND 14
Sunil 15
12 Tarun Null Jaipur 12
In order to see the records inserted in the table student in the above format we
use the select command in SQL.
mysql> Select * from student;
NOTE: * in the select
statement refers to all
the columns
6. Alter Table : This command can be used to add a new column ,
delete a column or to modify the definition of the existing columns.

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();

10. Drop Database: This command is used to permanently delete


/remove the database.
Syntax:
Drop database databasename;
Example:
mysql>drop database cl11;
11. Show databases: This command is
used to show the list of databases stored in my
system.
mysql> show databases;

12. Show tables: This command is used to


see the list of tables available in the currently
opened database.
Syntax:
Show tables;
Example:
mysql>show tables;

You might also like