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

'Suman' Nani' Ram' Shiva': Update

The document discusses various SQL commands used to create and manipulate databases and tables, insert and manipulate data, perform aggregate functions and filtering with clauses like WHERE and HAVING, and join tables. Commands covered include CREATE, INSERT, ALTER, TRUNCATE, DROP, SELECT, UPDATE, DELETE, COUNT, SUM, GROUP BY, JOIN, and more.

Uploaded by

Sharath Reddy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

'Suman' Nani' Ram' Shiva': Update

The document discusses various SQL commands used to create and manipulate databases and tables, insert and manipulate data, perform aggregate functions and filtering with clauses like WHERE and HAVING, and join tables. Commands covered include CREATE, INSERT, ALTER, TRUNCATE, DROP, SELECT, UPDATE, DELETE, COUNT, SUM, GROUP BY, JOIN, and more.

Uploaded by

Sharath Reddy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SQL Commands

Existent Database – use <database name>


New Database – create database <database name>
New Table – create table <table name> (colm1 Dtyp , colm2 Dtyp ,…)
 Ex— create table emp (emid int, emname varchar(15), salary int)
Insert Command – insert into <table name> values (val1, val2, val3, …)
 Ex—insert into emp values(101,’suman’,50000)
 Ex(multiple values)—insert into emp values(102, ‘nani’ ,64000),
(103, ‘ram’ ,55000),….
Insert specific column – insert into emp (emid ,ename) values(105,
‘shiva’ )
Alter Command
 alter table emp add location nvarchar(20) /(adding new column)/
 alter table emp alter column ename varchar(20) /(column size
change)/
 alter table emp drop column location / (To delete column)/
Truncate Command – truncate table emp / (only data)/
Drop Command – drop table emp / ( total table deleted )/
Where Command – select * from emp where emid=101 /(it filters the
data)/
Update Command – update emp set ename= ‘kumar’
where emid = 101 /(It updates the specific row)
Delete Command – delete from emp where ename= ‘kumar’
Sum command – select sum(sal) from emp
Group by – select sum(sal),dpno from emp group by dpno
Count Command – select count (*) from emp
Count Group by Having – select count (*), dpno from emp
group by dpno
having count (*) >2
 Having must be use after Group by clause only.
 Group by clause must follow when column name is specified after
aggregate Function.
 Where Order by and Having will use only after Group by. We
cannot use Order and Having before Group by it’s a syntax error.
 Order of syntax Where, Group by, Having, Order by (or) where,
Group, Order by.
JOIN – select <column name>
From
<Left table name>
<Join condition>
<right table name>
On <left table>.<similar column name>=<right
table>.<sc>
Inner join – select *
left From
right Emp
full outer Inner join
Dpno
On emp.edno=Dpno.edno

 All joins follows same syntax except cross join

Cross join – select *


From
Emp, Dpno

You might also like