Showing posts with label Oracle. Show all posts
Showing posts with label Oracle. Show all posts

Thursday, May 26, 2011

Alter Table name in oracle

Alter Table name in oracle.
Here I have a table named Employee, I want to name its name from Employee to User. First we can create a table with name Employee.
create table Employee
(
Id int primary key ,
Name varchar2(100)
);

Next we can write the alter table statement to alter the table name. Please see the example.
ALTER TABLE Employee
RENAME to Users;

Alter column name in oracle

Alter column name in oracle.
Here I have a table named Employee, I want to rename column - Name to FullName.
First we can create a table with name Employee.
create table Employee
(
Id int primary key ,
Name varchar2(100)
);


Next we can write the alter table statement to alter the column name. Please see the example.
ALTER TABLE Employee
RENAME COLUMN Name to FullName;

Alter table in Oracle

Alter table to add column
CREATE Table Employee
(
Id int PRIMARY KEY ,
Name VARCHAR2(100)
);

ALTER TABLE Employee
ADD
(
Email VARCHAR2(50)
);

Alter table to drop constraint
CREATE TABLE Employee
(
Id INT NOT NULL,
Name VARCHAR2(100),
CONSTRAINT pk_Emploee_Id PRIMARY KEY (Id)
);

ALTER TABLE Employee
DROP CONSTRAINT pk_Emploee_Id
;


Alter table to add multiple columns
ALTER TABLE Employee
CREATE Table Employee
(
Id int PRIMARY KEY ,
Name VARCHAR2(100)
);

ADD
(
Email VARCHAR2(50),
Mobile VARCHAR2(20)
);

Create Table in Oracle

1. Simple Create table
CREATE TABLE Employee
(
Id INT ,
Name VARCHAR2(100)
);

2. Create table with primary key
CREATE TABLE Employee
(
Id INT primary key ,
Name VARCHAR2(100)
);

3. Create table with primary key constraint
CREATE TABLE Employee
(
Id INT NOT NULL,
Name VARCHAR2(100),
CONSTRAINT pk_Emploee_Id PRIMARY KEY (Id)
);