Components of SQL :
DDL – Data Definition Language
Create :– Create a new table.
Alter :– Modifies an existing database.
Truncate:– Remove all record from a table, including all spaces
allocated for the records are removed.
allocated for the records are removed.
Drop :– Deletes the entire table.
1. CREATE :- Used To Create Table
Syntax:
SQL> CREATE TABLE <TABLE_NAME>(
2 <COLUMN_1> DATATYPE (SIZE) [CONSTRAINTS],
3 <COLUMN_2> DATATYPE (SIZE) [CONSTRAINT],
4 <COLUMN_n> DATATYPE (SIZE) )
5 ;
Example:
SQL> CREATE TABLE EMPLOYEE(
2 EMP_NO NUMBER PRIMARY KEY,
3 EMP_NAME VARCHAR(20) NOT NULL,
4 LOCATION VARCHAR(20))
5 ;
Table Created.
2. ALTER :- To Modify Existing Database
Syntax:
SQL> ALTER TABLE <TABLE_NAME>
2 (ALTER_STATEMENT) <COLUMN_NAME> (SIZE)
3 ;
Example:
SQL> ALTER TABLE EMPLOYEE
2 DROP COLUMN LOCATION
3 ;
Table Altered.
SQL> ALTER TABLE EMPLOYEE
2 ADD ADDRESS varchar(20)
3 ;
Table Altered.
3. TRUNCATE :- Remove All Records From Table and Recreate
Table Structure
Table Structure
Syntax:
SQL> TRUNCATE TABLE <TABLE_NAME>
2 ;
Example:
SQL> TRUNCATE TABLE EMPLOYEE
2 ;
Table Truncated.
4. DROP :- To Delete Whole Table
Syntax:
SQL> DROP TABLE <TABLE_NAME>
2 ;
Example:
SQL> DROP TABLE EMPLOYEE
2 ;
Table Dropped.
DQL – Data Query Language
Select :– Retrieves certain records from one or more tables.
SELECT :- Fetch Data From Database
Syntax:
SQL> SELECT <COLUMN_NAME>
2 FROM <TABLE_NAME>
3 ;
SQL> SELECT *
2 FROM <TABLE_NAME>
3 ;
Example:
SQL> SELECT EMP_NO
2 FROM EMPLOYEE
3 ;
SQL> SELECT * FROM EMPLOYEE
2 ;
No comments:
Post a Comment