create table statement

create table test
( test_id number(20),
col1 varchar(2),
col2 varchar(2));

then i have
 select
col1,
col2
from table 2

what i want is when i insert data in test table test_id increment with value 1 so can we do this while creating table or while inserting rows.

test
test_id,col1,col2
1         qq    qqq

2          bb      cc
3       dd           eee

other question can i test code online.
sam2929Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DavidSenior Oracle Database AdministratorCommented:
I recommend that you create a sequence, and then reference it when you are creating new records.  A sequence allows for an unique set of numbers to be assigned within a range that you desiginate -- for a primary key like this, we usually begin at 1 and don't set an upper limit.  

Then, it's simply INSERT INTO test test_id, col1, col2 VALUES(your_sequence.nextval, some_col1, some_col2).
DavidSenior Oracle Database AdministratorCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
slightwv (䄆 Netminder) Commented:
>>then i have  select col1, col2from table 2
If you want to insert data from table test into table2 using a select, use row_number from your previous question:
http://www.experts-exchange.com/Database/Oracle/Q_28363623.html

If you want a distinct value on inserts, then use the sequence as dvz has suggested.
johnsoneSenior Oracle DBACommented:
What version are you using?  In Oracle 12, you can create a column as an identity.

Documentation here -> http://docs.oracle.com/database/121/SQLRF/statements_7002.htm#sthref5643

There are examples of how to use it if you scroll down.
Gerwin Jansen, EE MVETopic Advisor Commented:
You can test code online here: http://sqlfiddle.com/ (Oracle 11gR2 - should work fine for your queries).
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.