Explanation for create table..

Go down

Explanation for create table..

Post by Preethi Sudhkar on Wed Mar 24, 2010 1:12 pm

CREATE TABLE ord_sep AS SELECT * from ord_aug WHERE 1 = 2;

what does this 1=2 mean?? can nyone explain it, with an example..

Preethi Sudhkar

Posts : 3
Points : 5
Join date : 2010-03-04

View user profile

Back to top Go down

Re: Explanation for create table..

Post by jeeva on Wed Mar 24, 2010 1:39 pm

probably that table might contain a column named 1...with an entry 2 Smile

jeeva

Posts : 50
Points : 93
Join date : 2010-03-04

View user profile

Back to top Go down

Re: Explanation for create table..

Post by Preethi Sudhkar on Wed Mar 24, 2010 1:42 pm

No i dont think so:)

Preethi Sudhkar

Posts : 3
Points : 5
Join date : 2010-03-04

View user profile

Back to top Go down

Re: Explanation for create table..

Post by jeeva on Wed Mar 24, 2010 1:49 pm

i tried that n its creating a new table with the same column names without any entries as the condition doesn match any entry..

jeeva

Posts : 50
Points : 93
Join date : 2010-03-04

View user profile

Back to top Go down

Re: Explanation for create table..

Post by jeeva on Wed Mar 24, 2010 1:52 pm

hmmm i dono the exact purpose of 1=2... an empty table with same columns is created even without that where clause...

jeeva

Posts : 50
Points : 93
Join date : 2010-03-04

View user profile

Back to top Go down

Re: Explanation for create table..

Post by Mahee on Wed Mar 24, 2010 3:29 pm

Nothin its simple, whatever is there after where clause it takes it as a condition check. If that condition returns true then the statement before where will get excecuted...

try

sql> select * from <tablename> where 24=24;

It will check if 24 = 24 it will return true and the statement will be executed.

[edited]
Even if the condition is false the select statement is executed, displaying no rows selected...


Last edited by Mahee on Wed Mar 24, 2010 4:09 pm; edited 1 time in total
avatar
Mahee

Posts : 29
Points : 233
Join date : 2010-03-03
Location : Haldia

View user profile

Back to top Go down

Re: Explanation for create table..

Post by Preethi Sudhkar on Wed Mar 24, 2010 3:35 pm

okie thanx Smile

Preethi Sudhkar

Posts : 3
Points : 5
Join date : 2010-03-04

View user profile

Back to top Go down

Re: Explanation for create table..

Post by jeeva on Wed Mar 24, 2010 3:36 pm

but 1=2 wont return true right!!!

jeeva

Posts : 50
Points : 93
Join date : 2010-03-04

View user profile

Back to top Go down

Re: Explanation for create table..

Post by Maithreyi on Wed Mar 24, 2010 3:50 pm

Yes 1=2 is false.The table is created with the outline of the other table alone.

Eg : - CREATE TABLE ord_sep AS SELECT * from ord_aug WHERE 1 = 2;
will create a table ord_sep with the same fields as ord_aug.

But, CREATE TABLE ord_sep AS SELECT * from ord_aug will create ord_sep as an exact clone of ord_aug,i.e. not just the outline but the contents of ord_aug will be copied to ord_sep

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 30
Location : Haldia

View user profile

Back to top Go down

Re: Explanation for create table..

Post by Mahee on Wed Mar 24, 2010 4:07 pm

exactly,

whenever u execute,
sql> select * from <table> where <condition>

if condition return false, it doesnt mean that select statement is skipped. If Even the condition check return false, the select statement is executed displaying "no rows selected" as none of the tuples matches the criteria.

That is why no data is copied to the new table.
whereas while executing a command in which the condition check returns true and only the rows which satisfy the condition will be returned and those will be copied to the new table.

the condition 1=2 will be checked for each and every row of the table and no rows will be selected as that condition return false forever....
avatar
Mahee

Posts : 29
Points : 233
Join date : 2010-03-03
Location : Haldia

View user profile

Back to top Go down

Re: Explanation for create table..

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum