Posts

Showing posts with the label sql

What is Sequence | SQL Tutorial 18

What is Sequence A Sequence is Database Object and its completely independent object. Use - Sequence are used to generate sequential integers values. and we can also create primary key values by using sequences. Example-   Suppose you are submitting bank application form with fields name, surname, dob, gender and so on.. when you click on submit records is stored in a table. but there is one more column in a table that is serial number of customer that is automatically maintained. Syntax- create sequence sequence_name; // its will start with 1 and incremented by 1 by default. 1,2,3 Now suppose we have to generate value from 100 and incremented by 10.\ create sequence emp_no Start With 100 Incremented By 10; if You want to know current value of the sequence- CURRVAL if You want to know next value of the sequence-  NEXTVAL Practice-  Step-1 - create a table create table employee( emp_id number, name varchar2(100), dob date, salary number); Step-2- creat

What is Synonyms | SQL Tutorial 19

What is Synonyms Synonyms is a permanent alias name for table Types of synonyms- public synonyms - is used by all authenticate users. private synonyms - is only used by owner of the object. By Default a synonyms to be created as private synonyms. Syntax-  create synonyms synonyms_name For table_name; create synonyms eit For employee_info_table; // now you can use synonyms instead of table name like... select * from eit; Practice-  Step-1 - create a table create table employee( emp_id number, name varchar2(100), dob date, salary number); Step-2- create a synonyms create synonyms emp for employee // by default you can not create synonym you have to connect to DBA. Step-3- conn system // enter your password step-4- grant create synonyms to rahul (use your oracle name here) step-5 conn rahul/7533 Step-6- create synonyms again create synonyms emp for employee  Now apply some operation  select * from emp;

flow of co related sub query

Image

What is co related sub query | SQL Tutorial 17

Image
What is co related sub query Co-related sub query  - if a sub query depends on output generated by outer query. Use-     Get Department details which is having no employee right now.    Get Product details which sold to any single Customer. Co-related sub query Uses two operator EXISTS- get object details   if having something then use EXISTS operator between Inner and outer query. NOT EXISTS- get object details   if not having something then use NOT   EXISTS  operator between Inner and outer query. Syntax - select ..... from table_name where EXISTS/NOT EXISTS ( select..... from table_name2 where table1.pkcolum = table2fkcolum  ); Example get department details where having at least 1 employee select d.* from dept d where EXISTS (select e.empno from emp e where e.deptno =  d.deptno); get department details where not having at least 1 employee select d.* from dept d where NOT EXISTS (select e.empno from emp e where e.deptno =  d.deptno);

What is sub query | SQL Tutorial 16

What is sub query Sub query is a query with in other query is known is Sub query Use if you want to get data from table1 by using value form table2 we will go for subquery not for joins. syntax. select * from table_name where....(select * from table_name where...(select * from table_name)...)... // Inner most query execute first Type of Sub Query Single row sub query - the sub query which is returning only one output value. example- get department name of employee 708. select dname from department where deptno = (select deptno from employee where empno=708) example-  get department detailsof employee 708. select * from department where deptno = (select deptno from employee where empno=708) Multi row sub query - the sub query which is returning more than one output value. example-  get department detailsof employee 708.709 select dname from department where dept_no IN (select deptno from employee where empno IN( 708, 709)); If we want

What is Data Integrity Constraints | SQL Tutorial 15

What is Data Integrity Constraints Data Integrity means apply some business rules on data fields . for Example-  Employee id must be unique and not null. Employee salary should not be zero etc. Employee Table e_id             e_name             e_sal        e_designation                        100             Rahul                25000       software developer          // (valid record) 0                 duke                30000         manager            // (invalid because E_id must be greater than 0) 101             Shweta            0                Designer           // (invalid because E_sal must be greater than 0)        So this are basic standard that we must have to Follow. so we have constraints for avoiding invalid insertion of invalid record. Types of Data Integrity Constraints- Keys Constraints Unique not null primary key Domain constraints Check Referential Integrity Constraints Foreign Key Unique Key constraints - its

What are joins | SQL Tutorial 14

What are Joins Joins are used when we have to fetch data from multiple table with multiple conditions on column. we can also do this by Set Operators but there are a limitation set operator always work on single column and single column data. Example- we want to display name of employee and department of employee. so we have to fetch data from employee table and department table . Types of JOINS- Cross joins/cartesian product. Equi joins/Inner joins. Self joins outer joins. What is cross join or cartesian product cross join concept is similar to cartesian product in mathematics. suppose we have to tables with this data. table_a = {x, y, z}; table_b = {10, 20}; if we apply cross join here then we will get data like this. table_a x table_b = {(x, 10), (x, 20), (y, 10), (y, 20), (z, 10), (z, 20)} What is Equi join if we want to get only valid combination of records then we use Equi joins because in cross join we are getting all combination of data. sup

What is Logical Operator | SQL Tutorial 13

What is Logical Operator AND vs OR Logical operators are used to check certain condition or multiple condition. . For Example- If we want to check two or more than two condition in a single query and all condition must be true then we use - AND OPERATOR If we want to check two or more than two condition in a single query and any one condition will be true then we use -  OR OPERATOR AND ____ if we are looking for employee whose is manager and salary is greater than 50000. means here are two condition employee job is manager and salary is greater than 50000 Select * from employee where job="manager" AND salary>=50000; if we are looking for employee whose is manager and salary is greater than 50000 and city is indore. means here are two condition  employee job is manager  and  salary is greater than 50000 and city is indore Select * from employee where job="manager" AND salary>=50000 AND city="indore"; // it wil

What is Negation Operator | SQL Tutorial 12

What is Negation Operator NOT LIKE VS NOT BETWEEN VS NOT IN VS IS NOT NULL Negation Operator NOT BETWEEN, IS NOT NULL, NOT LIKE,NOT IN these operators are just opposite of special Operator. For Example- if we want to display salary not greater than 2000 and not less than 10000 use- BETWEEN if we want to display all employee whose surname is not null use- IS NULL if we want to display all employee whose firstname is not Rahul use- LIKE if we want to display all customer who are not in MUMBAI and Channai use- IN (Specific list) NOT BETWEEN _________ if we dont want record within a range then we use Between operator example if want all employee details whose salary is not between 5000 to 10000. Select * from employee where salary NOT BETWEEN '5000' AND '10000'; NOT IN __ if we dont want to display record with specific list. Example- List of employee whose salary is not 10000, 50000, 70000. select * from employee where salary NOT IN(

What is Special Operator | SQL Tutorial 11

What is Special Operator LIKE VS BETWEEN VS IN VS IS NULL Special Operator BETWEEN, IS NULL, LIKE,IN these operators are used when we display record with specific range, limit, or any specific record. For Example- if we want to display salary greater than 2000 and less than 10000 use- BETWEEN if we want to display all employee whose surname is null use- IS NULL if we want to display all employee whose firstname is Rahul use- LIKE if we want to display all customer who are MUMBAI and Channai use- IN (Specific list) BETWEEN _________ if we want record within a range then we use Between operator example if want all employee details whose salary between 5000 to 10000. Select * from employee where salary BETWEEN '5000' AND '10000'; IN __ if we want to display record with specific list. Example- List of employee whose salary is 10000, 50000, 70000. select * from employee where salary IN(10000, 50000, 70000); IS NULL _______ sel

What is Relational Operator | SQL Tutorial 10

What is Relational Operator When we have to fetch record within some condition then we use Relational Operator. for example Highest paid employee, number of employee whose salary is greater than 20000. LIKE: select * from employee where sal>20000;   //it will return all employee whose salary is greater than 20000.

What is Arithmetic Operator | SQL Tutorial 9

What is Arithmetic Operator Arithmetic Operator's are used to perform Arithmetic operation like +, -, *, /. For Example sum of salary, average salary etc. select 100+200 from student; // yes you can specify any table name here but we are printing more record means output 300 will be printed total number of records present in the table like:   100+200 //is the output title ------------- 300 300 300 .. and so on until visit all row of table Best way to do this select 100+200 from DUAl; //dual is a predefined table 100+200 ________    300 Another Example: _______________ Display 10% of current salary: select sal, (0.10*sal) "10 % of salary" from employee;

What is operators is sql | SQL Tutorial 8

What is operators is sql  The symbols which are used to perform logical and mathematical operations in SQL are called SQL operators. There are three types of Operators used in SQL. Basically when we have to perform any operation to fetch our Desired output then we use Operators. for example- sum of salary, average salary, highest paid employee etc. Types of Operators- Arithmetic Operators - Perform =, -, *, /,  % Relational Operators - ==, <=, >= , > , <  Special Operators - To Get Range, List, Null- Use BETWEEN, IN, IS NULL, LIKE  Negation Operators - its Reverse of Special Operators- NOT BETWEEn, NOT IN, NOL NULL, NOT LIKE. Logical Operators -  To Specify condition and selection is OR, AND

DmL command || Sql Tutorial -7

DML Command Insert Command Its used to insert the record into table example- Command for inserting single record insert into <table name> values(value1, value2...) Command for inserting multiple command at a time insert into <table name> values(&col1, &col2...., &coln); whenever you enter query like this it will ask you to like this - enter a value for column1- value1.. and then hit enter  - enter a value for column2- value2.. and then hit enter - enter a value for column3- value3.. and then hit enter Now it will show 1 row created  if you want to create more record use / and hit enter SQL> /   hit enter // it will Execute most recent query again //this will so again and so on... - enter a value for column1- value1..  and then hit enter  - enter a value for column2- value2..  and then hit enter - enter a value for column3- value3..  and then hit enter // if you will miss any value here that will be inserted as NULL value Update command Used to upda

DDL command || Sql Tutorial -6

DDL Command CREATE Command It is used to create any data base object like tables, views, indexes, sequences, synonyms , users, functions, procedures, triggers, packages and so on. HOW TO CREATE A TABLE?            syn: CREATE TABLE <table_name>             (              <colname1> DATATYPE (size),               <colname2> DATATYPE (size),                : : : :,                : : : :,             ); INSERT Command This command is used for inserting new records into the tables          Syntax:           INSERT INTO <table_name>[(col1, col2,...., col n)]           VALUES(val1, val2,.....,val n);                  NOTE:  i) If number of columns in the table and number of values inserting in to the table      are equal, then no need to specify column names while inserting records.            ii) Char, Varchar2 and date type values should be enclosed in Single Quotes.            iii) If Number of inserting values are less than the

DATATYPES in sql || Sql Tutorial -5

DATATYPES IN SQL  The data type represents the type of data to be entered into a column and Db engine can assign memory for thevalue entered into the column. There are 5 types of DataType in sql. String DataTypes Numeric DataTypes Date Datatypes Binary DataTypes LOB--Large Objects String Data Types These data types support sequence of character, digits and any symbol from keyboard. CHAR(size) It is used to store fixed length character strings. By default the size is 1 character, and max size is 2000 chars orbytes. Ex: student_id, email, address and so on VARCHAR2(size) It is used to store variable length character strings. No default size. we should specify size and max size is 4000 chars /bytes. Ex: emp names, addresses, descriptions, city names. LONG It is used to store variable length char data(similar to varchar2 data type) but max size is 2 GB NOTE: Only one long type column is allowed per a table. 1) NUMBER(Precision, [Scale])    It is used to store numb

SQL COMMANDS || Oracle SQL COMMANDS Sql Tutorial -3

Types of SQL commands 1) DDL(data definition language) commands:       Used to create or change or delete any data base objects CREATE ALTER DROP TRUNCATE RENAME 2) DML(data manipulation language) COMMANDS       Used to fetch data / enter new data/ changing existed data / deleting the data from table. INSERT  UPDATE  DELETE  TRUNCATE 3) DRL(dataretrieval language) Command     SELECT (logicalcommand) 4) DCL(DATA CONTROL LANGUAGE) COMMANDS     Used to control the access of data base objects. These commands are used by DBA (databaseadministrator) GRANT  REVOKE 5) TCL(TRANSACTION CONTROL LANGUAGE) COMMANDS      Used to save or cancel the actions/transactions made on table data. COMMIT  ROLLBACK  SAVEPOINT

Features of Sql * Plus

Features of Sql * Plus At a time only one query is allowed to execute Sql queries are not case sensitive Each query is terminated with ; ( semi colon ) SQL commands are ANSI standard ( American National standard institute )

What is sql definition(Structured query language). Sql Tutorial -2

Image
Structured query language It is a collection of pre defined commands and constructs with syntactical rules. 1. Sql is a client tool to interact with ORACLE DB /any DB 2. Sql is to be installed in to the system whenever we have installed the db software. 3. Client [Technical] requests should be submitted in the form of "Queries". 4. Queries are executed by SQL STMT EXECUTOR ( Oracle Db Engine ) 5. Queries are executed against database and output will be displayed on the Sql * plus window.

What is sql in Deep(Structured query language). Sql Tutorial -1

What is sql in Deep(Structured query language) Oracle was the first company to release a product that used the English-based Structured Query Language, or SQL. This language allows end users to extract information themselves, without using a systems group for every little report. Oracle’s query language has structure, just as English or any other language has structure. It has rules of grammar and syntax, but they are basically the normal rules of careful English speech and can be readily understood. What is SQL QUERIES It is known as data base language. It is used to communicate with any database. We can use this language constructs to write SQL QUERIES. What is SQL* PLUS SQL * PLUS is a default client tool and acts as an interface between client and database. What is SQL It is a collection of pre defined commands and constructs with syntactical rules