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

SQL- Syntax(All Queries)

The document provides an overview of SQL queries in MySQL, detailing the basic commands categorized into DDL, DML, and TCL. It explains how to create databases and tables, insert and display records, and modify table structures. Additionally, it highlights the differences between the DELETE and DROP TABLE commands, emphasizing the importance of proper syntax and case sensitivity in MySQL commands.

Uploaded by

prabhakaran4558
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 views7 pages

SQL- Syntax(All Queries)

The document provides an overview of SQL queries in MySQL, detailing the basic commands categorized into DDL, DML, and TCL. It explains how to create databases and tables, insert and display records, and modify table structures. Additionally, it highlights the differences between the DELETE and DROP TABLE commands, emphasizing the importance of proper syntax and case sensitivity in MySQL commands.

Uploaded by

prabhakaran4558
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

COMPUTER SCIENCE[083]

TOPIC: SQL- QUERIES

Dear Student, First Understand the BASIC commands in


MYSQL

DDL DML TCL


COMMANDS COMMANDS COMMANDS
CREATE TABLE INSERT COMMIT
ALTER TABLE DELETE SAVEPOINT
DROP TABLE UPDATE ROLLBACK

DDL commands: CREATE TABLE, ALTER TABLE, DROP


TABLE [shortly remember as CAD)

DML commands: INSERT, DELETE, UPDATE


Shortly abbreviated as (IDU)

SYNTAX OF CREATING DATABASE(MYSQL)

TO CREATE DATABASE IN MYSQL:

MYSQL> CREATE DATABASE SCHOOL;


TO OPEN AND USE DATABASE IN MYSQL:

MYSQL> USE SCHOOL;

Dear student , First we need to create DATABASE by USING


following Command
THEN , we should start Creating Table in MYSQL

TO CREATE TABLE IN MYSQL: (command)

Mysql> create table <tablename> (column1 datatype


constraint, column2 datatype constraint, column3 datatype
constraint, column4 datatype constraint, column5 datatype
constraint);
For example:
Mysql> CREATE TABLE EMPLOYEE(EMPID integer
PRIMARY KEY, EMPNAME CHAR(30) , AGE integer,
DOJ date, Addr varchar(40));

Dear student , Please Understand MYSQL – Is a query


language . IT IS NOT A PROGRAMMING language like
PYTHON.

IT IS NON- Case Sensitive.

TO INSERT THE ROW/RECORD of TABLE:

Mysql> insert into EMPLOYEE values


(1001,’baskar’,23,’2025-07-23’,’no.4 kasi street, chennai’);
Mysql> insert into EMPLOYEE values
(1002,’varun’,24,’2025-06-20’,’no.67 motilal street,
chennai’);

Mysql> insert into EMPLOYEE values


(1003,’jaya’,27,’2026-07-19’,’no.34 jaya street, chennai’);

TO DISPLAY THE RECORDS OF THE TABLE

>SELECT * FROM EMPLOYEE;


[To display all ROWS/COLUMNS of the table]

OUTPUT:
EMPID EMPNAME AGE DOJ Addr
1001 baskar 23 2025-07- no.4 kasi
23 street,
chennai
1002 varun 24 2025-06- no.67
20 motilal
street,
chennai
1003 jaya 27 2026-07- no.34 jaya
19 street,
chennai’

To display the Empid , EMPNAME from table employee

 SELECT empid,empname from Employee;

EMPID EMPNAME
1001 baskar
1002 varun
1003 jaya

 SELECT Age,DOJ from Employee;


AGE DOJ
23 2025-07-
23
24 2025-06-
20
27 2026-07-
19
 Select DOJ, ADDR from Employee;

DOJ Addr
2025-07-23 no.4 kasi street,
chennai

2025-06-20 no.67 motilal


street, chennai

2026-07-19 no.34 jaya street,


chennai’

To View the STRUCTURE of the TABLE:

 DESC EMPLOYEE; [OR]

 DESCRIBE EMPLOYEE;
To display All tables in MYSQL:
>SHOW TABLES;

To display all the Databases in Mysql:


 SHOW databases;

Dear student Don’t Forget:


*All Queries in mysql Compulsory end with ;

We can type Mysql command in Lowercase or Uppercase or


Sentence Case NO issues. ONLY command must be Proper.
That’s IT student
Next we will see the command How to delete one
Row/records of the table:

 DELETE FROM EMPLOYEE;


[To remove all the rows/records of table and make as empty
set as an OUTPUT]

To delete one PARTICULAR ROW/RECORD:


 Delete from Employee Where empid=1002;
(To erase varun row/record)
 Delete from employee where empname=’jaya’;
(To erase Jaya row/record)

To Update the records of the table (Mysql)


 Update <tablename> SET column=newvalue where
column=value;
FOR Example: [To update the age of an employee)
>Update EMPLOYEE SET AGE=25 where empid=1001;
EMPID EMPNAME AGE DOJ Addr
1001 baskar 25 2025-07- no.4 kasi
[update] 23 street,
chennai
(To update the name of employee by using command)

>Update EMPLOYEE SET empname=’baskaran’ where


empid=1001;

EMPID EMPNAME AGE DOJ Addr


1001 Baskaran 25 2025-07- no.4 kasi
[update] 23 street,
chennai

ALTER TABLE : it is used to alter or modify the column


field data type or size.

- IT IS USED To Add a NEW column in the existing table


or remove one column field from the table

SYNTAX: ( To add a new column mobile_no) in a table


employee
 ALTER TABLE EMPLOYEE ADD mobileno integer;

To remove column from the existing table :


>ALTER TABLE EMPLOYEE DROP COLUMN AGE;
(This command is used to remove column Age from table
employee)
TO ADD primary Key constraint to one column:

 ALTER TABLE employee ADD primary


key(mobile_no);
-This command is used to set Mobile no as primary key for
the table Employee.

To remove PRIMARY KEY CONSTRAINT:

 Alter table EMPLOYEE DROP primary Key;

To completely erase the ENTIRE TABLE:

 DROP TABLE < tablename>;


For example:

 DROP TABLE employee;

Dear student , Delete and DROP table totally different.

Delete command is used to delete the rows/records of the


table . whereas DROP TABLE command is used to erase the
entire table along with records of the table.

You might also like