Sie sind auf Seite 1von 2

Introduction The Structured Query Language (SQL) comprises one of the fundamental building blocks of modern database architecture.

SQL defines the methods used to create and manipulate relational databases on all major platforms. SQL commands can be divided into two main sublanguages. The Data Definition Language (DDL) contains the commands used to create and destroy databases and database objects. After the database structure is defined with DDL, database administrators and users can utilize the Data Manipulation Language to insert, retrieve and modify the data contained within it. Ex.No : 1 Date : Data Definition Language (DDL) commands in RDBMS. Aim To write queries using Data Definition Language (DDL) commands in RDBMS. Theory Data Definition Language The Data Definition Language (DDL) is used to Creating a table Altering table structure by adding, deleting or modifying columns Destroy databases and database objects. These commands will primarily be used by database administrators during the setup and removal phases of a database project. CREATE COMMAND CREATE command is used to Create tables that will contain data. Syntax CREATE TABLE [table name] ( [column definitions] ); CREATE TABLE personal_info (first_name varchar2(20) not null, last_name varchar2(20) not null, employee_id number not null) ; establishes a table titled "personal_info" in the current database. In our example, the table contains three attributes: first_name, last_name and employee_id. ALTER Once table created within a database, one may wish to modify the definition of it. The ALTER command allows you to make changes to the structure of a table without deleting and recreating it. For example, the command to add a column named salary to an existing table named personal_info would be: ALTER TABLE personal_info ADD salary number null ; The above command adds a new attribute to the personal_info table an employee's salary. Finally, the "null" keyword tells the database that it's OK for this field to contain no value for any given employee.

DROP The final command of the Data Definition Language, DROP, allows us to remove entire database objects from DBMS. For example, if we want to permanently remove the personal_info table that we created, following command is used: DROP TABLE personal_info; Practice Queries. 1. Create a table named EMPLOYEES with following Structure Data Employee Number Employee Name Nature of Job Manager Joined Date Salary Department Number Field Name EMPNO ENAME JOB MGR HIREDATE SAL DEPTNO Data Type number(4) varchar2(30) varchar2(10) number(4) date number(7,2) number(2)

2. Create a table named DEPARTMENT with following Structure Data Department Number Department Name Location Field Name DEPTNO DNAME LOC Data Type number(2) varchar2(30) varchar2(30)

3. Create a table named SALARYGRADE with following Structure Data Grade Lowest Salary Highest Salary Field Name GRADE LOSAL HISAL Data Type varchar2(2) number(7,2) number(7,2)

4. Add the constraint not null to columns employee name and Employee Number in Employee Table 5. Create a table named PROJECT with following Structure Data Project Number Project Name Project Manager Persons Budjet Project Start date Project End Date Result Thus Queries using DDL commands in RDBMS were successfully executed. Field Name PNO PNAME PMGR PERSONS BUDGET PSTART PEND Constraint pk primary key unique not null, not null Data Type number(3) varchar2(60) number(4) number(5) number(8,2) date date

Das könnte Ihnen auch gefallen