Basics of Database Part 3
SQL Command Groups
DDL( Data Definition Language): Creation of Objects
DML( Data Manipulation Language): Manipulation of data
DCL( Data Control Language): Assignment & removal of permissions
TCL( Transaction Control Language): Saving and restoring changes to a database.
DDL( Data Definition Language)
Create: Creates object in the database/database objects.
Alter: Alters the structure of the database/database objects
Drop: Delete Objects from the database
Truncate: Remove all records from the table permanently
Rename: Rename an object.
Syntax: create table table name(
column name data type,
column n data type,
primary key (one or more columns)
);
Exp: create table emp(
emp_id int(10) not null,
first_name varchar(20),
last_name varchar (20) not null,
salary int (10) not null,
primary key (emp_id)
);
How to see the created table?
Syntax: select * from table name;
Exp: select * from emp;
How to see the logic of created table?
Syntax: describe table name;
Exp: describe emp;
How to add a new column in a table?
Syntax: alter table table name add column column name data type;
Exp: alter table emp add column contact int(10);
How to rename a column in a table?
Syntax: alter table table name rename column column name to new column name;
Exp: alter table emp rename column contact to job_code;
How to delete records from table?
Syntax: truncate table table name;
Exp: truncate table emp;
How to delete a table?
Syntax: drop table table name;
Exp: drop table emp;
DML( Data Manipulation Language)
How to insert data into the table?
Syntax: insert into table name ( column 1, column 2, ..... column n)
values
(values 1, values 2, ......., values n);
Exp: insert into emp (emp_id, first_name, last_name, salary)
values
(101, 'Robin', 'Sharma' , 100000);
How we can update something in the table?
Syntax: update table name set column 1 = value 1
where [condition];
Exp: update emp set last_name='Cholen' where emp_id=101;
If we need to delete something
Syntax: delete from table name where column name where (condition);
Exp: delete from emp where emp_id = 101;
DCL: Data Control Language)
Grant: Give access privileges to the database.
Syntax: grant <privilege list> on <relation name> to <user>
Revoke: Withdraws access privileges given with the grant command.
Syntax: revoke <privilege list> on <relation name> to <user>
TCL(Transaction Control Language)
Commit: Saves the work done.
Rollback: Restore the database to the origin state since the last commit.
Savepoint: Identify a point in a transaction to which you can roll back later.
#work #sql #day3 #database #language
Mail id: arpitmishra1629.ftp@gmail.com
Contact no: 8127430702
Linkedin: https://www.linkedin.com/in/arpit-mishra-9319b5131
👍
ReplyDelete