Zusammenfassung der Ressource
MySQL
- Data types
Anmerkungen:
- https://www.youtube.com/watch?v=7fOdo8PhPaw&list=PL_RGaFnxSHWr_6xTfF2FrIw-NAOo3iWMy&index=7
- Numeric
type
- BigInt (Really Larger Numebrs)
- Int (Big Values)
- Small Int (-32,768 to 32, 767)
- Tinyint (0 to 255)
- Decimal (m,d)
- Numeric (same As Decimal)
- Float (m,d)
- Date and Time
Data Type
- Datetime (YYYY-MM-DD HH:MM:SS)
- Date
Anmerkungen:
- MySQL - (YYYY-MM-DD)
Oracle - (DD-MMM-RR)
- Question
Anmerkungen:
- How to See the Format in results ?
- Time (HH:MM:SS)
- Year (YYYY)
- Character Type
- Char (M)
- Varchar (M)
- Text (to store large
amount of text)
- Blob (binary large object) -
for storing images
- Questions
Anmerkungen:
- Unable to change the Column data type from Numeric to INT in SQL Deveopler tool... Why?
Can we change the data type after table is created via SQL commands ??
- Constraints
Anmerkungen:
- https://www.youtube.com/watch?v=bIFB-rz315U&index=8&list=PL_RGaFnxSHWr_6xTfF2FrIw-NAOo3iWMy
- Not Null Constraint
Anmerkungen:
- If you want to make sure taht a field gets some value for every row in the table, apply the not null constraint to it.
- Default Constraint
Anmerkungen:
- If while populating a table you miss giving a colum some value, the default value will be used
- Unique constraint
Anmerkungen:
- Unique constraint makes sure that all values entered for the field on which the constraint applied are different
- Primary Key
Constraint
Anmerkungen:
- DDL
- Create Table
Anmerkungen:
- Name the Table
Define the Columns
Mention data types of columns
- Syntax
Anmerkungen:
- CREATE TABLE table_name (
col1 datatype,
col2 datatype,
.
.
col n datatype,
PRIMARY KEY (column));
- Example
Anmerkungen:
- CREATE TABLE employee (
id int PRIMARy KEY,
name varchar (50),
dob date,
email VARCHAR(50) )
===============
Create table emp_info as select id, name from employee;
- Questions
Anmerkungen:
- 1. How to check the Constraints of a table ?
2. How to see the list of tables in Oracle ? (SHOW Tables - in MySQL)
3. How to check the two tables are having same columns or not ?
4. DB defined column names - like - ROWID in Oracle DB ?
- Remove Table
Anmerkungen:
- Deleting a table from database. Make sure to ensure the table by using
1) SHOW TABLES
2) DESC table_name
- Syntax
Anmerkungen:
- Questions
Anmerkungen:
- How to Remove only data from table ?
any way to restore the deleted table ?
- TRUNCATE
- Syntax
Anmerkungen:
- DML
- INSERT
Anmerkungen:
- https://www.youtube.com/watch?v=Tet3Z7Yb2gg&list=PL_RGaFnxSHWr_6xTfF2FrIw-NAOo3iWMy&index=12
- Syntax
Anmerkungen:
- INSERT INTO table_name (Col 1, col3) VALUES (val 1, val 3)
====================
INSERT INTO table_name VALUES (val 1, val 2, .., val n)
>> order of the values need to be correct in second one
====================
INSERT INTO emp_info (id,name, dob, email)
select from id, name, dob, email
from employee.
>> we can insert the data from other table also.
- Questions
Anmerkungen:
- Can we avoid the column names, when inserting from another table like -
INSERT INTO emp_info (id,name,dob, email)
SELECT all FROM employee;
- SELECT
- Syntax
Anmerkungen:
- SELECT col1, col3,.., coln
FROM Table_name
- WHERE Clause
Anmerkungen:
- Used to mention the conditions & joining the differnt tables
- Syntax
Anmerkungen:
- SELECT col1 FROM table_name
[WHERE condition]
- TOP / LIMIT
Clause
Anmerkungen:
- Used to fect the top N number of records from query.
Not all DBs support
Oracle supports ROWNUM while MySQL uses LIMIT
- Syntax
Anmerkungen:
- MySQL -
SELECT Col-ListFROM table_name[WHERE condition]LIMIT n;
- ORDER BY Clause
- Syntax
Anmerkungen:
- SELECT col-list
FROM table_name
[WHERE Condition]
[ORDER BY Col2,Col4]
[ASC/DSC]
- GROUP BY Clause
Anmerkungen:
- GROUP BY always follow the WHERE Clause and must precede the ORDER BY clause
- Syntax
Anmerkungen:
- SELECT col-list
FROM table_name
Where Condition
[GROUP BY col]
[ORDER BY col]
- DISTINT
keyword
Anmerkungen:
- Used to fetch the single record only, when table is having the same value/data in multiple rows
- AS Clause
Anmerkungen:
- Giving different name to column headers in SELECT
- UPDATE
- Syntax
Anmerkungen:
- UPDATE table_name
SET col2=val2,..coln=valn
[WHERE condition]
- DELETE
- Syntax
Anmerkungen:
- DELETE FROM table_name
[WHERE condition]
- JOINS
- Syntax
Anmerkungen:
- SELECT e.ename, d.dname
From emp e join DEPT d
on e.deptno=d.deptno;
- Questions
Anmerkungen:
- Can we use JOINS for update / delete ?
- LEFT JOIN
- RIGHT JOIN
- FULL OUTER JOIN
- VIEW
Anmerkungen:
- View is same as a table without any storage.
- Syntax
Anmerkungen:
- CREATE VIEW EMP_VIEW AS
SELECT EMPNO,ENAME
FROM EMP
- SubQueries
- Operators
Anmerkungen:
- These are used with WHERE clause to limit the number of rows in output
- Arithmetic
- Addition (+)
- Subtraction (-)
- Multiplication (*)
- Division (/)
- Modular Division (%)
- Questions
Anmerkungen:
- SELECT 5 + 5;
is not working in SQL Developers.
May be we can't use SQL Developer as calculator ??
- Comparison
Anmerkungen:
- To compare data present in columns to data specified in conditions
- Equal (=)
- Not Equal (<>)
- Greater Than (>)
- Less Than (<)
- Greather Than or Equal To(>=)
- Lessthan Or Equal to (<=)
- Logical
- ALL
- AND
- BETWEEN
- IN
- LIKE
Anmerkungen:
- Used to compare a value to similar values in a table in database
Used with Wildcard characters - % (Percentage) & _ (underscore)
% - substitution for zero, one or many char's
_ - stands for one character or number
- Syntax
Anmerkungen:
- SELECT Column-list
FROM table_name
[WHERE col LIKE '_XXX%']
- OR
- IS NULL
- Functions
Anmerkungen:
- Map is for MySQL.
=========http://www.oracle-dba-online.com/sql/oracle_sql_functions.htm
- ABS
- ROUND
- DIV()
- MOD()
- CEIL
- FLOOR
- EXP(x)
Anmerkungen:
- LOG(X)
- POWER(X,Y)
- GREATEST(X,Y,Z)
- LEAST
- RADIANS
Anmerkungen:
- Not working in ORACLE SQL
- SQRT
- TRUNCATE
- RAND
- CONCAT
- UPPER
- LOWER
- INITCAP
- TRIM
- SUBSTR
Anmerkungen:
- select substr('mohammed sami',10,3) from dual;
Substr
--------
sam
- RIGHT
- LEFT
- LENGTH
- INSERT
- REPEAT
- REPLACE
- REVERSE
- STRCMP
- DATE & TIME
- ADDDATE
- SUBDATE
- DAYNAME
- CURDATE &
CURTIME
- NOW()
- MAKEDATE
- MONTHNAME
- TIMEDIFF
- TIME_TO_SEC
- Aggregate
- COUNT
- MAX
- MIN
- SUM
- AVERAGE