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

DB Lab 03

Create tables by specifying column names, data types, and constraints. Common data types include numbers, dates, characters, and binary files. For example, the command "CREATE TABLE Emp (Empno NUMBER(5), Ename VARCHAR2(15), Hiredate DATE, Sal NUMBER(7,2));" creates a table with four columns of the specified data types. Values can then be inserted into the table using the INSERT command and queried using SELECT.

Uploaded by

Attia Humaira
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)
41 views

DB Lab 03

Create tables by specifying column names, data types, and constraints. Common data types include numbers, dates, characters, and binary files. For example, the command "CREATE TABLE Emp (Empno NUMBER(5), Ename VARCHAR2(15), Hiredate DATE, Sal NUMBER(7,2));" creates a table with four columns of the specified data types. Values can then be inserted into the table using the INSERT command and queried using SELECT.

Uploaded by

Attia Humaira
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/ 6

LAB 03:

DATABASE

Fatima Jinnah Women University, Rawalpindi


SUBMITTED BY :

Attia Humaira (2019-BCS-013)

SUBMITTED TO:

Sir Adeel

BATCH:
BCS-IV(A)

DATE OF SUBMISSION:
February 19, 2021.
LAB 03:

“Datatypes and Creating Tables”


Tasks
  Unlock users
ALTER USER user_name IDENTIFIED BY password ACCOUNT UNLOCK;
  Designing Tables
Consider the following guidelines when designing your tables:
Use descriptive names for tables, columns, indexes, and clusters. Table Names, Columns Names can contain
maximum of 30 characters and they should start with an alphabet. Be consistent in abbreviations and in the
use of singular and plural forms of table names and columns.
Select the appropriate datatype for each column.
Arrange columns that can contain NULL Values in the last, to save storage space.
Before creating a table, you should also determine whether to use integrity constraints. Integrity constraints
can be defined on the columns of a table to enforce the business rules of your database automatically.
Before creating a Table you also have to decide what type of data each column can contain. This is known as
datatype. Lets Discuss what datatypes are available in Oracle.
 Datatypes

A datatype associates a fixed set of properties with the values that can be used in a column of a table or in an
argument of a procedure or function. These properties cause Oracle to treat values of one datatype
differently from values of another datatype. For example, Oracle can add values of NUMBER datatype, but
not values of RAW datatype.
Oracle supplies the following built-in datatypes:
Character datatypes

CHAR
NCHAR
VARCHAR2 and VARCHAR
NVARCHAR2
CLOB
NCLOB
LONG
Numeric datatypes

NUMBER
Time and date datatypes:

DATE
INTERVAL DAY TO SECOND
INTERVAL YEAR TO MONTH
TIMESTAMP
TIMESTAMP WITH TIME ZONE
TIMESTAMP WITH LOCAL TIME ZONE
Binary datatypes

BLOB
BFILE
RAW
LONG RAW
 Creating Tables in Oracle

Once you have designed the table and decided about datatypes use the following SQL
command to create a table.
For example, the following statement creates a table named Emp.
CREATE TABLE Emp (
Empno NUMBER(5),
Ename VARCHAR2(15),
Hiredate DATE,
Sal NUMBER(7,2)
);

To insert rows in the table you can use SQL INSERT command.
For example the following statement creates a row in the above table.

FATIMA JINNAH WOMEN UNIVERSITY

Department of Computer Science

SQL> insert into emp values (101,’Sami’,3400);

To insert rows continuously in SQL Plus you can give the following command.
SQL> insert into emp values (&empno,’&name’,&sal);

These &Empno, &name and &sal are known as substitution variables. That is SQLPlus will
prompt you for these values and then rewrites the statement with supplied values.
To see the rows you have inserted give the following command.
SQL> Select * from emp;
To see the structure of the table i.e. column names and their datatypes and widths. Give the following
command.
SQL> desc emp
To see how many tables are in your schema give the following command.
SQL> select * from cat;
or
SQL> select * from tab;
TASKS

You might also like