DATA TYPES OF SQL
INT - Whole Numbers
DECIMAL(M,N) - Integer where 'M' is Total no. of digits
and 'N' is no. of digits after decimal
VARCHAR(l) - String of length l
BLOB - Large files like Photos, PDF's,etc
DATE - YYYY-MM-DD
TIMESTAMP - YYYY-MM-DD HH:MM:SS
BASIC SYNTAX TO CREATE A TABLE:
CREATE TABLE <table_name> ( | - SUPPOSE THE TABLE NAME IS
student
student_id INT PRIMARY KEY, | - HERE student_id is the
column head, INT is the data type, PRIMARY KEY means that this column can not have
NULL value and it is unique
name VARCHAR(20), | - HERE name is the column head,
VARCHAR is the data type with length 20
subject VARCHAR(20) | - HERE subject is the column
head, VARCHAR is the data type with length 20
)
TO SEE ALL THE COLUMNS:
DESCRIBE <table_name>
TO DELETE A TABLE:
SYNTAX->
DROP TABLE <table_name>;
TO ADD A COLUMN;
SYNTAX->
ALTER TABLE <table_name> ADD <column_name> <column_dataype>;
FOR EG-
ALTER TABLE student ADD gpa DECIMAL(5,2);
TO DELETE A COLUMN:
SYNTAX->
ALTER TABLE <table_name> DROP COLUMN <column_name>;
TO INSERT DATA:
SYNTAX->
INSERT INTO <table_name> VALUES(<ALL THE VALUES>);
FOR EG-
INSERT INTO student VALUES(1,'Yuv','Mathematics')
TO GET ALL THE DATA:
SYNTAX->
SELECT * FROM <table_name>;
TO UPDATE DATA OF THE ROWS:
SYNTAX->