Вы находитесь на странице: 1из 5

EXNO: 1

AIM:

DDL (DATA DEFINITION LANGUAGE)

To create, alter, truncate and drop a table using DDL commands.. 1. Create Table Command Purpose: Creating a New Table Syntax: create table <table name> (Fieldname1 datatype, Fieldname2 datatype,); Creating a New Table from the Existing Table Syntax create table <new table name>(newFieldname1, newFieldname2,) as select oldFieldname1, oldFieldname2,from <old table name> 2 .Alter Table Command Syntax Adding new Fields alter table <table name> add (newFieldname1 datatype, newFieldname2 datatype,); Syntax Modifying Field Structure alter table <table name> modify (oldFieldname1 datatype, oldFieldname2 datatype,);

3.Truncate Table Command It is used to delete all the records stored in a table. But the structure of the table remains the same. Syntax: truncate table <table name>;

4.Drop Table It is used to drop table. The overall table structure is deleted. Syntax: drop table <table name>; 5.Describe Table This is used to display the structure of the table. Syntax: desc <table name>; Problem Definition: M/s. ABC Enterprise runs a large book store and keeps books on various subjects. The following are the requirements by the company to automate its activities through Website. * customers browse the catalogue of books and place the orders over the internet.

* It has mostly corporate customers who call the book store and give the ISBN number of a book and a quantity. M/s. ABC then prepares a shipment that contains the books they have ordered. Now create the database with the following: Relation ISBN Title Author Quantity- Instock Price Pub-Year : : : : : Books : ISBN number(PK)

: Title of the book Author of the book Available quantity in stock Book sales price Year published

Relation Cust- ID Cust-Name Address Card-NO : :

: :

Customers customer ID (PK) customer Name Address of the customer customers credit card number

Relation Order-NO cust- ID order-Date

orders

: order Number (PK) : References cust-ID of customers : order date

Relation Order-NO ISBN Quantity Ship-Date

: :

order-List (PK) : (PK), References ISBN of books

: Quantity ordered : Shipping date

Problem statement: 1. (a) create tables for the above entities using CREATE statement. Also use the integrity constrains. 1. (b) create a table using a sub- query. To Alter a table: 2. Create table test1 with the following attributes: emp-id, emp-name Create table department with attributes: dept-id, dept-name. Perform the following operations: Add a new column d-id to test 1 relation. Add constraints (PK, FK, UNIQUE, CHECK) to the above tables. Modify column(s) (data width, NOT NULL). Enable/disable constraints. Drop column(s)/constraints. Rename test1 relation into new name.

To create a view: 3. create a view which lists the cust-name, order-date. Quantity, ship-date from tables Books, customers, orders and order-list. Notify the changes reflected in the base tables when views are updated and vice versa. To Truncate table : 4. Truncate the tables. To drop a view. To drop a table. 5. Drop the above tables and view.

RESULT : Thus some basic operations are performed in oracle using DDL commands.

Вам также может понравиться