SQL Day-3
SQL Day-3
Business Organizations:
-----------------------------
Objectives of any BO, profit.
1. store and maintain business data in a secure and easily retrival manner.
Information : when we process the data , then we gets meaningfull results, this is
called infromation.
Datastore:
--------------
1. data maintainace.
2. data redundency.
3. data integrity
4. security
5. data retrival
to overcome these problems we need to store the data inside the DBMS s/w (RBDMS
s/w)
Database: it is a organized collection of interrelated data or structured
collection of data.
Mysql (Oracle)
Orcale s/w
postgres
ms-access
sql-server
db2
etc
--in order to work with RDBMS we need to use SQL (structured query language),it is
an interface by using which we can work with any kind of RDBMS s/w.
>show databases;
after creating the db inside the mysql rdbms s/w we need to move inside that db.
>use sb101db;
>show tables;
>create table student(roll int,name varchar(12),marks int);
or
>desc student;
Datatypes in mysql:
------------------------
1.numeric types
2. string types
1.numeric types
--------------------
tinyint : 1byte
smallint --2 byte
mediumint - 3byte
int ---4byte
bigint--8byte
floating point:
-----------------
2. string type:
----------------
2.varchar: variable length of string bt 1 to 65500, here we must define the length
e
ex:
char(4)
varchar(4)
value char(4) storage_required
Note: in the term of efficiency , if we r storing string with variable lenght the
we should use varchar, and if the length is always fixed then we should use char,
here char is slightly faster than varchar.
a. date yyyy-mm-dd
a.add
b. modify
c.drop
d.change
ex:
> alter table student add address varchar(15);
ex:
ex:
d. change:
ex:
ex:
DML (insert,update,delete)
1.insert:
---------
2.update:
3.delete:
-----------
--it is used to delete the records/rows from the table.
>delete from student; // it will delete entire record from the table like
truncate command.
DRL(select)
==========
syntax:
select col1,col2,..
from tablename
where condition
groupby colname
having condition
orderby colname [asc/desc]
ex1:
>select * from student; // all the column and all the rows
operators:
========
Note: this temparory name of a column we can not use inside where clause.
ex:
special operators:
---------------------
IN .... NOT IN
ex:
select * from student where sname LIKE 'r%'; : name should start with r