*SQL *- Structured Query Language-
- used in Data analysis.
- Software development purpose
- To manage and manipulate relational DBMS.
*Uses of SQL
*
- Querying the data. To find a specific information.
- To insert, update , delete the data.
**SQL commands
**
DDL- Data definition Language.
Used to define/ manage the tables.
The commands are,
- CREATE- Create a table
- ALTER- To modify the table structure, which was created already.
- DROP- To delete the complete table
- RENAME- To rename the table
- TRUNCATE- To delete all records except the table structure.
DML- Data manipulation language.
To manipulate the data into the table.
- INSERT- Add new data in rows.
- UPDATE- Modify the existing data. 3.DELETE- Remove data from the row.
DQL - Data Query Language
SELECT- To retrieve a data from the table.
( Select* from table name )
DCL- Data control language
- Used for access control
GRANT- To provide access/ privileges to users.
REVOKE- To take back the privileges.
TCL- Transaction control Language
Used to manage the transactions/ data.
COMMIT- used to permanently save any transaction into the database
ROLLBACK- Used to restores the database to the last committed state. undo the changes since last commit
SAVE POINT- Set a point to rollback
SET TRANSACTION- To set the properties for transactions ( Like read only )
DATA TYPES
1. Numeric Type
**
**SMALLINT- It saves whole numbers in the specified range. Memory 2 bytes
INTEGER-It saves whole numbers in the specified range.-Memory 4 bytes
BIGINT- Memory is 8 bytes
NUMERIC @ DECIMAL
REAL@ FLOAT4- Single precision floating point number-
Single-precision floating-point format (sometimes called FP32 or float32) is a computer number format, usually occupying 32 bits in computer memory; it represents a wide dynamic range of numeric values by using a floating radix point.
DOUBLE PRECISION @FLOAT8 - Double-precision floating-point numbers are 64-bit floating-point numbers used to represent real numbers with greater precision and a wider range than single-precision floating-point numbers. This format, often referred to as FP64, is commonly used in scientific computing and other applications where high accuracy is crucial.
*2. CHARACTER
*
CHAR (n)- fixed length character string.
ex, USA,IND
VARCHAR (n)- Lengthy character string.
TEXT- Variable length characteristics.
( unlimited length )
*3. BOOLEAN TYPE
*
TRUE or FALSE.
4. DATE AND TIME TYPES
DATE- date
TIMESTAMP- (date and time )
To launch, psql -h localhost -U postgres
Create- CREATE DATABASE Students ;
drop- DROP DATABASE STUDENTS
TO view DATABASE - \L
To close- \q
alter/ edit - ALTER DATABASE Students RENAME TO Students_details;
\c Students; - to connect the DB.
CREATE TABLE students_info ( Name varchar(50), Class INTEGER, Joining_date DATE);
*to view- \dt
*
Top comments (0)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.