SQL MikeDane
SQL MikeDane
Database(DB):
Any collection of related information :Phonebook,todo list,your 5 best
friends,facebook's User base ,shopping list
DBMS : A special software program that helps users create and maintain a database
*Makes it easy to manage large amount of information
*Handles Security
*Backups your data
*interacts with software applications
*importing and exporting data
4)Data Manipulation Language(DML) : *Used for inserting ,updating and deleting data
from database
Queries : A Query is a set of instruction given to the RDBMS (written is SQL) that
tell the RDBMS what information you want it to retrieve for you.
*Tons of data in a DB
*Often hidden in a complex schema
*Goal is to only get the data you need
PRIMARY KEY(student_id)
);
update mate
ALTER TABLE student ADD gpa DECIMAL(3,2);
you have to specific entery mate use thay like koi column ma entery na hoy te na
mate here major nathi so ana mate null aave.
INSERT INTO student(student_id,name) VALUES(3,'kathan');
mare name null na joietu hoy to NOT NULL use karvanu column ma first
UNIQUE bhi lakiye to particular column unique
starting ma lakhvanu
DEFAULT 'undecided',
primary key ni jagyae Auto_INCREMENT,
lakiye to jate key increment thaya kare. and also insert values db ma lakhvu na
pade specifically .
UPDATE student
SET major = 'Undecided';
UPDATE student
SET name = 'Johnny'
WHERE student_id = 4;
UPDATE student
SET major = 'Biological Sciences'
WHERE major = 'Biology';
UPDATE student
SET major = 'Biosociology'
WHERE major = 'Biology' OR major = 'sociology'
UPDATE student
SET major = 'Undecided', name = 'Tom'
WHERE student_id = 4;
Basic Queries :
SELECT *
FROM student;
SELECT *
FROM student
WHERE name = 'Jack';
SELECT *
FROM student
WHERE student_id > 2;
operation : <> means not equal ,<,>,AND,OR,>=
SELECT *
FROM student
WHERE major <> 'Biology';
SELECT *
FROM student
WHERE major = 'Biology' AND student_id > 1;
alpabatically order ma name print thay . bydefault assending order ma print thay
but if you want to print descending order then you have to mention DESC;or ASC
SELECT *
FROM student
WHERE name IN ('Karan','Meet','Darshna');
so means table ni ander aa 3 na name hoy to data aave .jenu name hoy ano data
display thay
IN company db when we create first table that time we cannot declare fk later we
can declare.
whenever we create fk that time also REFERENCES we have to write ON DELETE (CASCADE
OR SET NULL.)
FOREIGN KEY(mgr_id) REFERENCES employee(emp_id) ON DELETE SET NULL
SELECT *
FROM employee;
-- Find all employee's id's and names who were born after 1969
SELECT emp_id, first_name, last_name
FROM employee
WHERE birth_day >= 1970-01-01;
-- Find all employees who are female & born after 1969 or who make over 80000
SELECT *
FROM employee
WHERE (birth_day >= '1970-01-01' AND sex = 'F') OR salary > 80000;
Functions in SQL :
block of the code ,avg,counting ,....
Aggregation :
WildCards:koi specific find karvu hoy ana mate use thay che
(-- % = any # characters), (_ = one character)
this is pattern symbol
UNIONS : is basically a special sql which we can use to combine the results of
multiple select statements into one .
On Delete set null : : ma je id or name aapau hoy te null thay che like if i say
id then only is null in fk table
but in
On Delete Cascade : ma aakhi row j delete thai jay che ae row no badho data delete
thai jay che sathe fk table ma bhi hoy to ama bhi aakhi row delete thai jay che..