SQL: Structured Query Language basics
Structured query language is abbreviated as SQL. SQL has three classification of command languages, they are :
- DDL: Data Definition Language
- DM: Data Manipulation Language
- TCL: Transaction Control Language
These three command languages help one to access SQL, using this one can create, update, manipulate, save and delete database tables.
DDL
DDL or Data Definition Language is used to describe the basics of a table, it defines the database tables. In this we have following commands:
- Create
This command is used to create a new table in a database.
Code: >>create table tablename ();
>> create table employee ();
The above command creates a table with name employee but this table will have no attributes in it. To add attributes we have to write in this form;
>>create table employee (empname varchar2 (30),
empno number (4),
empbranch varchar2 (10));
The above table is now created with three attributes employee name as empname; employee number as empno; employee branch as empbranch.
- Alter
Alter can be used in two ways:
- To add a new column:
>>alter table employee add (empcity varchar2(20));
This adds a new column to table employee named employee city as empcity.
- For modification of existing table (empno number(5));
>>alter table employee modify (empno number(5));
This modifies table employee, it column empno with datatype number (4) to number (5).
- Drop
This helps in dropping the table or delete the whole table from the database.
>>drop employee;
- Desc
This command describes the table and its columns having its type and other attributes.
>>desc employee;
- Truncate
This command is used to delete all the data from the table;
>> truncate table employee; //this delete all the data from the table.
Stay connected to our next post we will be dealing with DML And TCL.
Hit like if you found this post useful.