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

Database & SQL

The document provides an introduction to advanced server-side issues including data, databases, database management systems (DBMS), structured query language (SQL), and common SQL commands and functions. It defines data and databases, explains what a DBMS is and common examples. It also describes what SQL is used for, common SQL commands like select, insert, update, and delete, and functions such as count, avg, sum, between and like.

Uploaded by

Khagesh Josh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

Database & SQL

The document provides an introduction to advanced server-side issues including data, databases, database management systems (DBMS), structured query language (SQL), and common SQL commands and functions. It defines data and databases, explains what a DBMS is and common examples. It also describes what SQL is used for, common SQL commands like select, insert, update, and delete, and functions such as count, avg, sum, between and like.

Uploaded by

Khagesh Josh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

INTRODUCTION TO

ADVANCED SERVER SIDE


ISSUES
What is DATA?

 DATA is collection of raw fact.


 For example your name, age, height, weight, etc are some data related to you.
 A picture , image , file , pdf etc can also be considered data.
What is database?

 Database is a systematic collection of data. Databases support storage and  manipulation of data.
Databases make data management easy.
  Database is a collection of inter-related data which helps in efficient retrieval, insertion and deletion
of data from database and organizes the data in the form of tables, views, schemas, reports etc. 
 An online telephone directory would definitely use database to store data pertaining to people, phone
numbers, other contact details, etc.
 Your electricity service provider is obviously using a database to manage billing , client related
issues, to handle fault data, etc.
What is DBMS

  The software which is used to manage database is called Database Management System
(DBMS).
 For Example, MySQL, Oracle etc. are popular commercial DBMS used in different
applications.
 It also helps to control access to the  database.
 Database Management Systems are not a new concept and as such had been first
implemented in 1960s.
SQL

 SQL stands for Structured Query language, pronounced as "S-Q-L" or sometimes as


"See-Quel".
 SQL is the standard language for dealing with Relational Databases.
 SQL can be used to insert, search, update and delete database records.
 SQL can do lots of other operations including optimizing and maintenance of databases.
 Relational databases like MySQL Database, Oracle, Ms SQL server, Sybase, etc uses
SQL.
 Example: select * from students where class=“BCA”
What can SQL do?

 SQL can execute queries against a database


 SQL can retrieve data from a database
 SQL can insert records in a database
 SQL can update records in a database
 SQL can delete records from a database
 SQL can create new databases
 SQL can create new tables in a database
 SQL can create stored procedures in a database
 SQL can create views in a database
 SQL can set permissions on tables, procedures, and views
SQL Commands

 SQL commands are instructions. It is used to communicate with the database. It is also
used to perform specific tasks, functions, and queries of data.
 SQL can perform various tasks like create a table, add data to tables, drop the table, modify
the table, set permission for users.
 There are five types of SQL commands: DDL, DML, DCL, TCL, and DQL.
Types of SQL command
Create and Drop Database

 CREATE DATABASE databasename;
 Example Create database BCA

 DROP DATABASE databasename;


 Example Drop database BCA
Create table

 CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
   ....
);
 The column parameters specify the names of the columns of the table.

 The datatype parameter specifies the type of data the column can hold (e.g. varchar, integer, date, etc.).
 CREATE TABLE Students(
    ID int,
    LastName varchar(255),
    FirstName varchar(255),
    Address varchar(255),
    Phone varchar(255)
);
Drop table

 DROP TABLE table_name;
 Drop table Students;
SQL Constraints

 SQL constraints are used to specify rules for data in a table.


 CREATE TABLE table_name (
    column1 datatype constraint,
    column2 datatype constraint,
    column3 datatype constraint,
    ....
);
SQL Constraint
 Constraints are used to limit the type of data that can go into a table. This ensures the accuracy and
reliability of the data in the table. If there is any violation between the constraint and the data action, the
action is aborted.
 Constraints can be column level or table level. Column level constraints apply to a column, and table level
constraints apply to the whole table.
 The following constraints are commonly used in SQL:
 NOT NULL - Ensures that a column cannot have a NULL value
 UNIQUE - Ensures that all values in a column are different
 PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table
 FOREIGN KEY - Uniquely identifies a row/record in another table
 CHECK - Ensures that all values in a column satisfies a specific condition
 DEFAULT - Sets a default value for a column when no value is specified
 INDEX - Used to create and retrieve data from the database very quickly
Insert into table

 Syntax :
 INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...)
OR
 INSERT INTO table_name
VALUES (value1, value2, value3, ...);
Update table

 UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

 Example
 Update students set name=“Seema” where id=3;
Delete

 Syntax: DELETE FROM table_name WHERE condition;
 Example : Delete from Students where id=4;
Select

 SELECT * FROM table_name
 SELECT col1,col2 from table_name
 Select distinct col1,col2 from table_name
 Select * from table_name where address=“Bhaktapur”
 Select * from table_name where name=“sudip”
SQL min max

 SELECT MAX(column_name)
FROM table_name
WHERE condition;

 SELECT MAX(column_name)
FROM table_name
WHERE condition;
SQL Between operator

 SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
Like operator

 The LIKE operator is used in a WHERE clause to search for a specified pattern in a
column.
 There are two wildcards often used in conjunction with the LIKE operator:
 % - The percent sign represents zero, one, or multiple characters
 _ - The underscore represents a single character
 SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;
 SELECT name
WHERE students LIKE ’a%’;
SQL COUNT(), AVG() and SUM() Functions

 SELECT COUNT(column_name)
FROM table_name
WHERE condition
 SELECT AVG(column_name)
FROM table_name
WHERE condition;
 SELECT SUM(column_name)
FROM table_name
WHERE condition;

You might also like