0% found this document useful (0 votes)
3 views4 pages

Lab 1&2

Uploaded by

70137141
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Lab 1&2

Uploaded by

70137141
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

LAB 1&2

Lab1

Task: Installation and introduction of DB & DBMS

Lab2:

DDL Statement for Creating a Table

How to create Database/Schema:

Syntax:

CREATE DATABASE databasename

Syntax:

CREATE TABLE tablename

(columnname datatype(size), columnname datatype(size));

Example:

CREATE TABLE client_master (

client_no VARCHAR(6),

name VARCHAR(20),

address1 VARCHAR(30),

address2 VARCHAR(30),

city VARCHAR(15),

state VARCHAR(15),

pincode NUMBER,

bal_due NUMBER

);

This creates a table named client_master with columns like client_no of type VARCHAR(6), name of
type VARCHAR(20), and others with specified data types and sizes.

2. Creating a Table from an Existing Table

Syntax:

CREATE TABLE TABLENAME

[(columnname, columnname, ………)]

AS SELECT columnname, columnname… FROM tablename;

CREATE TABLE new_client_master ( c_no VARCHAR(6), c_name VARCHAR(20), c_address1


VARCHAR(30) ) AS SELECT client_no, name, city FROM client_master;
Example:

CREATE TABLE new_client_master

AS SELECT client_no, name, city FROM client_master;

This creates a new table named new_client_master and copies data for columns client_no, name,
and city from the client_master table.

3. Insertion of Data into Tables

Syntax:

INSERT INTO tablename [(columnname, columnname, ………)]

VALUES (expression, expression);

Example:

INSERT INTO client_master (client_no, name, city)

VALUES ('C001', 'John Doe', 'New York');

This inserts a new row into the client_master table with client_no as 'C001', name as 'John Doe', and
city as 'New York'.

4. Inserting Data into a Table from Another Table

Syntax:

INSERT INTO tablename

SELECT columnname, columnname, ……. FROM tablename;

Example:

INSERT INTO new_client_master

SELECT client_no, name, city FROM client_master;

This inserts data into the new_client_master table by selecting client_no, name, and city from the
client_master table.

5. Insertion of Selected Data into a Table from Another Table

Syntax:

INSERT INTO tablename

SELECT columnname, columnname…….. FROM tablename

WHERE columnname = expression;

Example:

INSERT INTO new_client_master

SELECT client_no, name, city FROM client_master

WHERE city = 'New York';


This inserts data into the new_client_master table by selecting rows where city is 'New York' from
the client_master table.

6. Retrieving All Data from a Table

Syntax:

SELECT * FROM tablename;

Example:

SELECT * FROM client_master;

This retrieves all columns and rows from the client_master table.

7. Retrieving Specific Columns from a Table

Syntax:

SELECT columnname, columnname, …. FROM tablename;

Example:

SELECT client_no, name FROM client_master;

This retrieves only the client_no and name columns from the client_master table.

8. Elimination of Duplicates from the Select Statement

Syntax:

SELECT DISTINCT columnname, columnname FROM tablename;

Example:

SELECT DISTINCT city FROM client_master;

This retrieves distinct values from the city column of the client_master table, eliminating duplicates.

9. Selecting a Data Set from Table Data

Syntax:

SELECT columnname, columnname FROM tablename

WHERE searchcondition;

Example:

SELECT client_no, name FROM client_master

WHERE city = 'New York';

This retrieves client_no and name for rows where city is 'New York' from the client_master table.

Creating the Requested Tables


1. client_master Table:

CREATE TABLE client_master (

client_no VARCHAR(6),

name VARCHAR(20),

address1 VARCHAR(30),

address2 VARCHAR(30),

city VARCHAR(15),

state VARCHAR(15),

pincode NUMBER,

bal_due NUMBER

);

2. product_master Table:

CREATE TABLE product_master (

product_no VARCHAR,

description VARCHAR,

profit_percent NUMBER,

unit_measure VARCHAR,

qty_on_hand NUMBER,

reorder_lvl NUMBER,

sell_price NUMBER,

cost_price NUMBER

);

These CREATE TABLE statements define the columns, their data types, and sizes as specified.

You might also like