SlideShare a Scribd company logo
DATABASE BASIC
MD.WALIUZZAMAN
1.DATABASE CREATE:
CREATE DATABASE mydb
mydb
2.DATABASE RENAME:
ALTER DATABASE mydb MODIFY NAME= mynewdb
mynewdb
Method:1
Method:2
Sp_renameDB ‘mynewdb’ , ‘mydb’
mydb
3.DROP DATABASE
DROP DATABSAE mydb
mydb
4.CREATE TABLE
CREATE TABLE mytable
(
id int primary key ,
name nvarchar(50) not null,
age int(20)
)
NEED: TABLE NAME, COLOMN NAME ,DATA TYPE+SIZE.
OPTIONAL:CONSTRAINTS(such as primary key, check constraints)
mytable
VIEW TABLE PROPERTY
EXEC sp_help mytable
5.INSERT DATA IN TABLE
INSERT INTO mytable
VALUES ( 1,`wali`,25)
Method:1(single row insert)
Method:2(multirow insert)
INSERT INTO mytable
(id,name,age )
VALUES ( 1,`wali`,25), ( 2,`akash`,26);
6.UPDATE DATA IN TABLE
UPDATE mytable
SET name =‘batash’ ,age=25
WHERE id=2;
7.DELETE DATA IN TABLE
DELETE mytable WHERE id=1;
Delete select value:
Delete all value:
DELETE FROM mytable
Delete full table:
DROP TABLE mytable
8.BASIC SELECT STATETMENT
SELECT * FROM mytable;
Show all values in table:
Show selected one column values:
SELECT age FROM mytable;
Show selected multiple column values:
SELECT age,name FROM mytable;
9.SELECT STATEMENT
SELECT DISTINCT
name FROM mytable
(USING DISTINCT)
10.SELECT STATEMENT
For using WHERE Clause
at first we need to know about
WHERE Clause operators
(USING WHERE Clause)
WHERE Clause OPERATORS
=, >, <, >=, <=, <>, !=, !>, !<
AND,OR,NOT
BETWEEN
LIKE
IN
ALL,ANY,SOME
EXISTS
11.SELECT STATEMENT
SELECT * FROM mytable WHERE age = 25
SELECT * FROM mytable WHERE age != 25
SELECT * FROM mytable WHERE age = 25 AND name = ‘wali’
SELECT * FROM mytable WHERE age = 25 OR name = ‘wali’
SELECT * FROM mytable WHERE name LIKE ‘w%’
SELECT * FROM mytable WHERE name LIKE ‘%wa%’
SELECT * FROM mytable WHERE name NOT LIKE ‘%wa%’
SELECT * FROM mytable WHERE name = ‘aksh’ OR name = ‘wali’
SELECT * FROM mytable WHERE name IN (‘aksh’,‘wali’)
SELECT * FROM mytable WHERE EXISTS (SELECT id FROM
mytable2 WHERE fee>500)
(USING WHERE Clause)
12.SELECT STATEMENT
SELECT * FROM mytable ORDER BY
age DESC
(USING ORDER BY Clause)part-1
SHOW ALL VALUES:
SELECT * FROM mytable ORDER BY
age ASC
ASC=ascending;
DESC=descending
Note:
13.SELECT STATEMENT
SELECT name FROM mytable ORDER
BY name DESC
(USING ORDER BY Clause)part-2
SHOW SELECTED COLUMN VALUES:
SELECT name FROM mytable ORDER
BY age ASC
ASC=ascending;
DESC=descending
Note:
14.SELECT STATEMENT
Creating Groups of data
15.SELECT STATEMENT
AGGREGATE MEANS
SUM(numeric)
AVG(numeric)
MIN/MAX(int,datetime,varchar,..)
COUNT(*)-return number of rows
AGGREGATE (USING GROUP BY Clause)
16.SELECT STATEMENT
AGGREGATE (USING GROUP BY Clause)
SELECT id ,SUM(salary) FROM mytable
GROUP BY id
17.SELECT STATEMENT
SELECT id ,SUM(salary) as totalsalary
FROM mytable GROUP BY id
AGGREGATE (USING GROUP BY Clause)
18.SELECT STATEMENT
SELECT id ,SUM(salary) as totalsalary,
AVG(salary) as aversalary FROM mytable
GROUP BY id
AGGREGATE (USING GROUP BY Clause)
19.SELECT STATEMENT
SELECT COUNT(*) FROM mytable
AGGREGATE (USING GROUP BY Clause)
20.SELECT STATEMENT
(USING JOIN Clause)
JOIN
INNER JOIN OUTER JOIN FULL JOIN CROSS JOIN
LEFT JOIN RIGHT JOIN
21.SELECT STATEMENT
At first we need two table
(USING JOIN Clause)
22.SELECT STATEMENT
Simple basic command:
(USING JOIN Clause)
SHOW ALL VALUES FROM BOTH TABLE
INNER JOIN
SELECT * FROM student INNER JOIN
guardian
On student.studentid=guardian. guardianid
23.SELECT STATEMENT
Here is output:
(USING JOIN Clause)
Before joining
After joining
24.SELECT STATEMENT
advance command:
(USING JOIN Clause)
SHOW selected column VALUES FROM BOTH TABLE
INNER JOIN
25.SELECT STATEMENT
INNER JOIN
(USING JOIN Clause)
SELECT s.studentid as ‘id student table’,
g.studentid as ‘id guardian table’,
s.name,g.fathername,g.mothername
FROM student s INNER JOIN guardian g
On s.studentid=g.studentid
s=student table
g=guardian table
26.SELECT STATEMENT
(USING JOIN Clause)
Before joining
After INNER joining
27.SELECT STATEMENT
BASIC
(USING JOIN Clause)
OUTER JOIN
LEFT RIGHT
COLUMN COLUMN
RIGHT
JOIN
LEFT
JOIN
27.SELECT STATEMENT
advance command:
(USING JOIN Clause)
SHOW selected column VALUES FROM BOTH TABLE
OUTER JOIN
(LEFT JOIN)
28.SELECT STATEMENT
OUTER JOIN –(LEFT JOIN)
(USING JOIN Clause)
SELECT s.studentid as ‘id student table’,
g.studentid as ‘id guardian table’,
s.name,g.fathername,g.mothername
FROM student s LEFT JOIN guardian b
On s.studentid=g.studentid
s=student table
g=guardian table
29.SELECT STATEMENT
(USING JOIN Clause)
Before joining
After LEFT joining
30.SELECT STATEMENT
advance command:
(USING JOIN Clause)
SHOW selected column VALUES FROM BOTH TABLE
OUTER JOIN
(RIGHT JOIN)
31.SELECT STATEMENT
OUTER JOIN –(RIGHT JOIN)
(USING JOIN Clause)
SELECT s.studentid as ‘id student table’,
g.studentid as ‘id guardian table’,
s.name,g.fathername,g.mothername
FROM student s RIGHT JOIN guardian b
On s.studentid=g.studentid
s=student table
g=guardian table
32.SELECT STATEMENT
(USING JOIN Clause)
Before joining
After RIGHT joining
33.SELECT STATEMENT
(USING JOIN Clause)
FULL JOIN
34.SELECT STATEMENT
FULL JOIN
(USING JOIN Clause)
SELECT s.studentid as ‘id student table’,
g.studentid as ‘id guardian table’,
s.name,g.fathername,g.mothername
FROM student s FULL JOIN guardian b
On s.studentid=g.studentid
s=student table
g=guardian table
35.SELECT STATEMENT
(USING JOIN Clause)
Before joining
After FULL joining
33.SELECT STATEMENT
(USING JOIN Clause)
CROSS JOIN
To be continue..............
FLASH BACK
1.DATABASE— create,rename,delete
2.TABLE— CREATE, data INSERT+UPDATE ,
data+table DELETE
FLASH BACK
a.basic select statement
b. select statement—(using distinct)
c.(using where clause)+where clause operators
d.order by clause(asc,desc)
e.group by clause(aggregate—sum,min/max,avg,count)
f.join—inner,outer(left+right),full join,
3.SELECT STATEMENT:
33.SELECT STATEMENT
(USING JOIN Clause)
CROSS JOIN
33.SELECT STATEMENT
(USING JOIN Clause)
CROSS JOIN
Wali
Akash
Reza
Foyel
Murad
Haider
diit
horizone
33.SELECT STATEMENT
(USING JOIN Clause)
CROSS JOIN
diit_table horizone_table
33.SELECT STATEMENT
(USING JOIN Clause)
CROSS JOIN
SELECT
diit_student_name,
horizon_student_name
FROM diit_table
CROSS JOIN
horizon_table
33.SELECT STATEMENT
(USING JOIN Clause) CROSS JOIN
diit_table horizone_table
BEFORE
JOINING
After CROSS JOINING

More Related Content

PPT
Creating a database
PDF
MySQL for beginners
DOCX
supporting t-sql scripts for Heap vs clustered table
DOC
Ex[1].3 php db connectivity
PPTX
Mysql Crud, Php Mysql, php, sql
PDF
Sql queries - Basics
PPT
PPTX
Obtain better data accuracy using reference tables
Creating a database
MySQL for beginners
supporting t-sql scripts for Heap vs clustered table
Ex[1].3 php db connectivity
Mysql Crud, Php Mysql, php, sql
Sql queries - Basics
Obtain better data accuracy using reference tables

What's hot (18)

PPTX
PostgreSQL's Secret NoSQL Superpowers
PPTX
Avinash database
PDF
SXML: S-expression eXtensible Markup Language
PDF
Database Systems - SQL - DDL Statements (Chapter 3/2)
PPTX
DDL(Data defination Language ) Using Oracle
PPT
My sql presentation
KEY
Zf Zend Db by aida
PDF
Chapter 4 Structured Query Language
PPTX
Introduction to SQL (for Chicago Booth MBA technology club)
PPTX
Sql Basics And Advanced
PPTX
SQL Commands
DOC
A must Sql notes for beginners
PPTX
Introduction to SQL
PPTX
Introduction to (sql)
PPTX
Lab2 ddl commands
PPT
PPT
Introduction to-sql
PostgreSQL's Secret NoSQL Superpowers
Avinash database
SXML: S-expression eXtensible Markup Language
Database Systems - SQL - DDL Statements (Chapter 3/2)
DDL(Data defination Language ) Using Oracle
My sql presentation
Zf Zend Db by aida
Chapter 4 Structured Query Language
Introduction to SQL (for Chicago Booth MBA technology club)
Sql Basics And Advanced
SQL Commands
A must Sql notes for beginners
Introduction to SQL
Introduction to (sql)
Lab2 ddl commands
Introduction to-sql
Ad

Viewers also liked (10)

PPTX
basic database concepts
PPTX
Database management system basic, database, database management, learn databa...
PPTX
RDBMS.ppt
PPTX
Rdbms
PPT
Types dbms
PPTX
Types of databases
PPTX
Introduction to database
PPT
Basic DBMS ppt
PPTX
Dbms slides
basic database concepts
Database management system basic, database, database management, learn databa...
RDBMS.ppt
Rdbms
Types dbms
Types of databases
Introduction to database
Basic DBMS ppt
Dbms slides
Ad

Similar to MS SQL Database basic (20)

PPT
Mysql 120831075600-phpapp01
DOCX
Msql query
PPTX
Its about a sql topic for basic structured query language
PPT
MY SQL
PDF
Basics on SQL queries
PPTX
MySqL_n.pptx edshdshfbhjbdhcbjdchdchjcdbbjd
DOC
Best sql plsql material
PPTX
Structured Query Language(SQL)
PDF
Sql commands
PPTX
DBMS - Presentationhgfhfhfghfghfhfgh.pptx
RTF
Best sql plsql_material for B.TECH
PPTX
rdbms parul university oracle dbms bca mca
ODT
PDF
dbms.pdf
PDF
Master SQL from Scratch_ Beginners to Advanced 📝.pdf
PDF
sql ppt for students who preparing for sql
PPTX
Java class 8
DOC
Introduction sql
PPTX
Mysql 120831075600-phpapp01
Msql query
Its about a sql topic for basic structured query language
MY SQL
Basics on SQL queries
MySqL_n.pptx edshdshfbhjbdhcbjdchdchjcdbbjd
Best sql plsql material
Structured Query Language(SQL)
Sql commands
DBMS - Presentationhgfhfhfghfghfhfgh.pptx
Best sql plsql_material for B.TECH
rdbms parul university oracle dbms bca mca
dbms.pdf
Master SQL from Scratch_ Beginners to Advanced 📝.pdf
sql ppt for students who preparing for sql
Java class 8
Introduction sql

Recently uploaded (20)

PDF
Basic Mud Logging Guide for educational purpose
PDF
RMMM.pdf make it easy to upload and study
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Cell Types and Its function , kingdom of life
PPTX
Pharma ospi slides which help in ospi learning
PPTX
GDM (1) (1).pptx small presentation for students
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
master seminar digital applications in india
PDF
Classroom Observation Tools for Teachers
PDF
Complications of Minimal Access Surgery at WLH
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
Basic Mud Logging Guide for educational purpose
RMMM.pdf make it easy to upload and study
2.FourierTransform-ShortQuestionswithAnswers.pdf
Cell Types and Its function , kingdom of life
Pharma ospi slides which help in ospi learning
GDM (1) (1).pptx small presentation for students
VCE English Exam - Section C Student Revision Booklet
TR - Agricultural Crops Production NC III.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Microbial disease of the cardiovascular and lymphatic systems
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Anesthesia in Laparoscopic Surgery in India
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
master seminar digital applications in india
Classroom Observation Tools for Teachers
Complications of Minimal Access Surgery at WLH
PPH.pptx obstetrics and gynecology in nursing
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
102 student loan defaulters named and shamed – Is someone you know on the list?

MS SQL Database basic