Types of SQL Language |
What is Data Definition language?
DDL is used to build/ modify the structure of a database.
Commands included in DDL are :
- create
- alter
- drop
- truncate
CREATE A DATABASE
Create database dbname;
Create database dbname;
DROP DATABASE
drop database dbname;
drop database dbname;
CREATING TABLE
create table tablename (col1 datatype primary key not null, col2 datatype not null);
or
create table tablename (col1 datatype not null, col2 datatype not null, primary key(col1));
create table tablename (col1 datatype primary key not null, col2 datatype not null);
or
create table tablename (col1 datatype not null, col2 datatype not null, primary key(col1));
DROPPING TABLE
drop table tablename;
drop table tablename;
ADDING NEW COLUMN
alter table tablename add column datatype;
DROPPING COLUMN
alter table tablename drop column columnname;
TRUNCATE TABLE
truncate table tablename;
What is Data Manipulation language?
1. DML is used to manipulate the data present in the tables.
2. DML includes
- retrieval of information.
- insertion of new information.
- Updation of information
- Deletion of existing information.
3. DML is of 2 types:
- Procedural - user specifies what the data is and how to get the data
- Non Procedural - user specifies what the data is but does not specify how to get the data.
4. Commands included in DML are :
- select
- insert
- update
- delete
DISPLAYING ALL COLUMNS OF TABLE
select * from tablename;
select * from tablename;
INSERTING VALUES IN TABLE
insert into tablename (col1 int, col2 varchar(20), col3 real, col4 date) values (1, 'any text', 32, 200.00,'2001-07013')
insert into tablename (col1 int, col2 varchar(20), col3 real, col4 date) values (1, 'any text', 32, 200.00,'2001-07013')
UPDATING TABBLE
update tablename set col1 = val1, col2= val2 where condition;
update tablename set col1 = val1, col2= val2 where condition;
DELETE QUERY
delete from tablename where condition;
Get PostgreSQL/ MySQL all queries cheat sheet formulas CLICK HERE
delete from tablename where condition;
Get PostgreSQL/ MySQL all queries cheat sheet formulas CLICK HERE