SQL
SQL
2) alter command: it is used to altering the existing table. Like adding a new
column, delete the existing column or modify the existing column, etc.
Syntax:
A lter table <table name><add/drop/modify>
(<col name>datatype(<size>), ….. ….. ….. …..);
Eg:
i)add a new column
alter table employee add (dob date,
mobile number(10));
ii)drop a table column
alter table employee drop(mobile);
iii) modify a column
alter table employee modify(salary number (10,2));
4) drop command: this is used to delete all rows with table structure.
Syntax:
drop table <table name>;
[varchar,varchar2,char=takes in ‘ ‘]
b)insert into <table name> values (<list of values>);
Eg:
insert into employee
values(102, 45000, ’Raj’, ‘2 feb 2001’ );
[order should be same as declared]
if we use values format then we have to give all the values, if we do not
know then use “null”
NULL in databases
1) In databases or SQL, we have a special value called naull.
2) This value is inserted in every column for which we do not provide any
specific value.
Eg:
Q) delete the record of the employee ‘Jyoti’.
delete from employee where ename='Jyoti';
Truncate
-DDL command
-it can’t be rolled back.
- removes all the rows.
-fast
2) select *
from employee;
COLUMN ALIASING
select id as empid, salary as income , ename
from employee;
#TCL
1)commit command: saves in disk
2)rollback command: undo
3)savepoint
SOME COMMANDS
1) select * from tab; = shows all the existing tables
2) desc <table name> = gives the structure of table(shows col names and
their data types)
3) select * from employee; = shows the table
4) select sysdate from dual; = tells the system date [dd-mon-yy]
5) clear scr
#OPERATORS IN SQL
operators are symbols or words that represent an action or process.Overall SQL
provides us 4 categories of operators which are shown below:
-Arithmetic
-Comparison
-Logical
-Miscellaneous
ARITHMETIC OPERATORS
+(unary), -(unary), /, * , + , -
COMPARSION OPERATORS
=(this is also assignment when used with set) equality
<>, !=, ^= not equality
>
<
>=
<=
LOGICAL OPERATOR
(non-case sensitive)
AND Logical Conjunction operator
OR Logical Disjunction operator
NOT Logical Negation operator
MISCELLANEOUS OPERATORS
|| Concatenation
IN ,NOT IN Comparison for a value in a specified list
BETWEEN , NOT BETWEEN Comparison based on range of values
LIKE , NOT LIKE pattern
IS, IS NOT
#GROUP FUNCTIONS
Till above all were Scalar queries.
When we do al the rows collectively, they are called Group Functions.
Done through Vector queries.
Group functions in SQL are those built-in functions which operate on group of
rows.
Thus, rather than operating on one row at a time they operate on multiple
rows but return a single result. Due to this, they are also called Vector or
Aggregate Functions.
Oracle provides 5 group functions and they are:
-SUM
-MAX
-MIN
-AVG
-COUNT //NON-CASE SENSITIVE
Q) wap to display total expense as well as avg expense done by the company
on the salary of employees
select sum (salary), avg(salary)
from employee;
Q) wap a query to display highest salary
select max(salary)
from employee;
select count(*)
from employee;
select count (job) =>5
from employee;