0% found this document useful (0 votes)
3 views

DBMS langages-1-4

The document outlines the Data Definition Language (DDL) and Data Manipulation Language (DML) commands for managing database tables. It includes examples of creating, altering, renaming, truncating, and dropping tables, as well as inserting, selecting, updating, and deleting records. Each command is accompanied by SQL queries and their expected outputs.

Uploaded by

Thendral
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

DBMS langages-1-4

The document outlines the Data Definition Language (DDL) and Data Manipulation Language (DML) commands for managing database tables. It includes examples of creating, altering, renaming, truncating, and dropping tables, as well as inserting, selecting, updating, and deleting records. Each command is accompanied by SQL queries and their expected outputs.

Uploaded by

Thendral
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

DATA DEFINITION LANGUAGE

EX NO: 1A

1. TABLE CREATION

a.New table creation:


Query 1: CREATE TABLE EMP (EMPNO NUMBER (4), ENAME VARCHAR2
(10),DESIGNATIN VARCHAR2 (10),SALARY NUMBER (8));
Output: Table created.
Query 2: desc emp
Output:

b. Create a Table from Existing Table with All Fields

Query 1: Create table emp5 as (select *from emp);


Output: Table created.
Query 2: desc emp5
Output:

c. Create a table from Existing Table with Selected Fields

Query 1: CREATE TABLE EMP2 AS SELECT EMPNO, ENAME FROM EMP;


Output: Table created.
Query 2: desc emp2
Output:

2. DESC (DESCRIBING TABLE)


Query 1: desc emp2
Output:
3. ALTER/ MODIFY
a. Modify on a Single Column:

Quary 1: ALTER TABLE EMP MODIFY EMPNO NUMBER (6);


Output: Table altered.
Query 2: desc emp
Output:

b. Alter table with multiple column:


Query 1: ALTER TABLE EMP MODIFY (EMPNO NUMBER (7), ENAME VARCHAR2(12));
Output: Table altered.
Query 2: desc emp
Output:

c. TO add a new column:


Query 1: ALTER TABLE EMP ADD QUALIFICATION VARCHAR2(6);
Output: Table Altered
Query 2: desc emp
Output:
d. TO add a new multiple column:
Query 1: ALTER TABLE EMP ADD (DOB DATE, DOJ DATE);
Output: Table Altered
Query 2: desc emp
Output:

4. Rename:
a. Rename Table name:
Query1: RENAME EMP to EMP10;
Output: Statement processed.
Query 2: desc EMP10
Output:

5. TRUNCATE:
This command is used to delete all records stored in a table, but the structure of the table is retained.
SQL> truncate table mad;
Table truncated.
SQL> select*from mad;
no rows selected
Query1: truncate table emp1;
Output: Table truncated.

6. DROP
Query 1: drop table emp1; Query 2 : desc emp1;
Output:

ORA-06550: line 3, column 13: PL/SQL: ORA-00942: table or view does not exist ORA-06550: line 3, column 1:
PL/SQL: SQL Statement ignored ORA-06550: line 4, column 13: PL/SQL: ORA-00942: table or view does not
exist ORA-06550: line 4, column 1: PL/SQL: SQL Statement ignored
DATA MANIPULATION LANGUAGE (DML)
(Insert, select, update and delete commands)
EX NO 1B
1. Insert
Query 1: Create table: CREATE TABLE EMP (EMPNO NUMBER (4),ENAME VARCHAR2
(10),DESIGNATION VARCHAR2 (10),SALARY NUMBER (8));
Query 2: To insert: INSERT INTO EMP VALUES (101,'NAGARAJAN','LECTURER',15000);
Query 3: Output: 1 row(s) inserted.
Query 4: select *from emp;
Output:

2. SELECT
Query 1: select *from emp;
Output:

SELECT COMMAND USING 'WHERE' CLAUSE


Query 2: select * from EMP where designation= 'LECTURER' and salary='15000';
Query 3: select *from emp;
Output:

3. UPDATE
UPDATE COLUMN
Query 1: UPDATE EMP SET SALARY = 16000,designation='LECTURER' WHERE EMPNO=101;
Query 2: select *from emp;
Output: 1 rows updated
Query 3: select *from emp;
Output:

4. DELETE
Query 1: DELETE EMP WHERE EMPNO=101;
Output: 1 row(s) deleted.
Query 2: select *from emp;
Output : no data found

You might also like