#SQL Commands:
==============
- The way we use to give the instructions/request to computer by using other programming language like C , C++, Java etc..
- We can use sql commands to give insructions to database to perform communicaiton as well other set of operations/tasks, functions, firing queries on data of the table.
- Operation : Create a table, add/insert data to a table, delete a table, change the structure of a table, providing/revoking permission to users.
- Also used to manipulate data in RDBMS.
Types of SQL Commands:
=======================
5 types of sql commands
1) DDL
create, alter, drop, truncate, rename
2) DML
insert, update, delete
3) DCL
grant, revoke
4) TCL
commit, rollback, savepoint
5) DQL
select
1) DDL (Data Definition Language):
----------------------------------
DDL changing the structure of the table : create a table, alter a table, delete a table, drop table, rename
- all DDL commands a committed automatically once their TX completes.
create: Create a new table or create a new database
alter: altering command used for adding new column, change size, datatype
drop: drop table
truncate : removes/deletes the data from table
rename: rename a table
- Create a database:
------------------
- Creating a database using create DDL command
Syntax:
create database [databaseName];
Ex:
Create database EnggcollegeJJM;
1)If not exists:
create database if not exists jjm;
if exists:
- create: Create a new table or create a new database
-------------------------------
syntax:
create table tableName(columnName1 Datatype,columnName2 Datatype,......);
create table if not exists tableName(columnName1 Datatype ,columnName2 Datatype,......);
create table tableName(columnName1 Datatype [attributes],columnName2 Datatype,......);
create table student(id int, name varchar(25), email varchar(25),dob date);
create table if not exists student(id int, name varchar(25), email varchar(25),dob date);
Create a table with all datatypes supported by mysql:
----------------------------------------------------
create table employee(eid int autoincrement,name varchar(20), gender varchar(6),dob date, salary float(10,2));
5 сен 2024