Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating A Table

Status
Not open for further replies.

FontanaS

Programmer
May 1, 2001
357
US
In my stored procedure I want to check to see if a table exists, and if it does not then I want to create it based on another database table.

The stored procedure is in database x
If not exists (table) then
create table (that is the same as the table (same name) in database y)

Can I create a table that is like a copy of one that already exists in another database .

Both databases are within the same server


THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!11
 
Something like:


This is not exact SQL but it should work in the main (you need to read in the count into some variable etc)

select count(*) from systables where table_name = xxxx
if count(*)>0
return
else
CREATE TABLE XXXXXX AS SELECT * FROM YYYYYYY [WHERE SOMECOLUMN = SOMEVALUE] Cal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top