Create n tables with different number names

Hi guys, I work with SQL Server 2008 and OS Windows Server 2008 R2 64 bits. I have to create 10 tables with different names e.g. 'Image1', 'Image2', and so on. For this goal, I use a loop and concatenation. Here is the code:
DECLARE @i INT
DECLARE @v_table_n CHAR
SET @i=1
SET @v_table_n='Image'
WHILE (@i<=10)
BEGIN
    DECLARE @STR VARCHAR(100)
       SET @STR = 'CREATE TABLE SQL_DB_Filestream.dbo.Image1' + @v_table_n + CAST(@i AS VARCHAR(10)) + ' (
       [ID_RowFeatVec] INTEGER NOT NULL PRIMARY KEY,
       [CF1] FLOAT,
       [CF2] FLOAT,
       [CF3] FLOAT
       EXECUTE @STR
    SET @i = @i + 1;
END
GO
As a result, an error message appears:
"The name 'CREATE TABLE SQL_DB_Filestream.dbo.Image1I1 (
    [ID_RowFeatVec] INTEGER NOT NULL PRIMARY KEY' is not a valid identifier."
I have tried a lot of versions but it doesn't work.
What am I doing wrong?
Best wishes
SV_proj

>> I have to create 10 tables with different names e.g. 'Image1', 'Image2', and so on. For this goal, I use a loop and concatenation. Here is the code: <<
1) An SQL Programmer would write ten CREATE TABLE statements. Are you old enough to know about Rube Goldberg? He was a cartoonist who invented inanely complex device for simple task!
2) Ten identical tables is a huge design flaw. It is so awful I want to use it in one of my books. Tables are sets. A set is completed whole, or as Cantor said “a many that is treated as a one” (it sounds cool in German or Esperanto). 
3) We hate loops in SQL. This is a declarative language. I will bet you have no idea what that means. 
What you want to do is mimic a magnetic tape file system from the 1950's. We used to put a label on the tapes based on the date or a sequence number. Not a completed whole. 
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • Is it possible to create a Synonym with different column names

    Hi,
    I want to create a Synonym with different columns names (Columns not in original table) . I am not sure if this can be done . Any suggessions...
    Thanks in advance....

    Synonyms are not limited to tables. Accroding to the SQL Reference, a synonym is:
    an alternative name for a table, view, sequence, procedure, stored function, package, materialized view, Java class schema object, user-defined object type, or another synonym.
    In fact, synonyms are not even validated until they are used:
    SQL> create synonym my_synonym for table_which_does_not_exist;
    Synonym created
    SQL> select * from my_synonym;
    select * from my_synonym
    ORA-00980: synonym translation is no longer valid

  • How to create a table with varied number of columns?

    I am trying to create a balance table. The colunms should include years between the start year and end year the user will input at run time. The rows will be the customers with outstanding balance in those years.
    If the user input years 2000 and 2002, the table should have columns 2000, 2001, 2002. But if the user input 2000 and 2001, the table will only have columns 2000 and 2001.
    Can I do it? How? Thanka a lot.

    Why did you create a new thread for this?
    How to create a table with varied number of columns?

  • Many to many join table with different column names

    Hi have a joint table with different column names as foreign keys in the joining
    tables...
    e.g. i have a many to many reltnshp btwn Table A and Table B ..and join table
    C
    both have a column called pk.
    and the join table C has columns call fk1 and fk2
    does cmd require the same column name in the join table as in the joining table?
    are there any workarounds?
    thanks

    HI,
    No, the foreign key column names in the join table do not have to match the primary
    key names in the joined tables.
    -thorick

  • How to create a table with auto number?

    I want to create a table with a column default to increasing integer. The first thought came up to me is to use sequence. I find in google the following create statement create table etl_stats1 (run_time date,arr_rows int,lid int default nextval('etl_req'));get ORA-04044: procedure, function, package, or type is not allowed here.
    There are threads metioned using trigger to do the job. But does what not support default to a sequence, it appears such a nature way.

    You need to create a sequence and a trigger:
    SQL> create table etl_stats1 (run_time date,arr_rows int,lid int)
      2  /
    Table created.
    SQL> create sequence etl_seq;
    Sequence created.
    SQL> create or replace
      2    trigger etl_stats1_bir
      3    before insert
      4    on etl_stats1
      5    for each row
      6    begin
      7        select etl_seq.nextval into :new.lid from dual;
      8  end;
      9  /
    Trigger created.
    SQL> insert into etl_stats1 (run_time,arr_rows) values(sysdate,99)
      2  /
    1 row created.
    SQL> select * from etl_stats1
      2  /
    RUN_TIME   ARR_ROWS        LID
    15:38:41         99          1
    SQL> SY.

  • Is it possible to create Order type with different number ranges-Plant wise

    Hi Experts
    Client wants to get the different number ranges for the order types created in the different plants. Is there any user exit for the same.
    I have assigned the order type to the different plants. And Order type is assigned to a no range. So whenever a order type is created in different plants; order types uses the same number ranges.
    so with this situation one cann't know the total no. of order created within a plant.
    Is there any solution for the same.
    Pease give your valuable solutions.
    Regards
    Pankaj

    Hi
    Best way is to create different order types for different plants.
    like we have order types OR15 ,OR20 & OR30 for different plants 1500 ,2000 & 3000 .
    you can assign different number range for different order type.
    this is simplest solution.
    Regards
    Sujit

  • How to join two columns between two tables with different column names

    Hi
    How i can join 2 columns with different names between the 2 tables.
    Can any one please give solution for this.
    Thanks
    Manu

    Hi,
    basic understanding of joins:
    If you want to join 2 tables there should be matching column w.r.t. data and it's data type. You need not to have same column names in both the tables...
    so, find those columns which has got same values..

  • Is it possible to have 2 tables with the same name in an Orable database?

    Hello,
    I'm a complete Oracle newbie so please excuse my question if it's stupid.
    I was trying to create 2 tables with the same name using different tablespaces but it does not seem to work. Like this (second time just change the name of the tablespace):
    CREATE TABLE test_tbl (
      id INTEGER,
      status VARCHAR2(10),
      last_modified DATE DEFAULT SYSDATE
    TABLESPACE tblspc1Is it in general in Oracle possible to acquire this goal?
    Thanks a lot!
    P.S. I have already created the needed tablespaces
    CREATE TABLESPACE tblspc1 DATAFILE 'tblspc1.dbf' SIZE 10MEdited by: 808239 on 02-Mar-2011 02:18

    It is not possible to create two tables with same name in same schema.
    A user can own one schema with his own name and another with the schema name SYS.
    For this you have to grant sysdba privilage to the user and then have to connect using sys password or with the password specified in password file.
    But this still you have to access to the table in sys schema using sys.table_name.
    Hope Answered tthe Question.

  • How can i export the data to excel which has 2 tables with same number of columns & column names?

    Hi everyone, again landed up with a problem.
    After trying a lot to do it myself, finally decided to post here..
    I have created a form in form builder 6i, in which on clicking a button the data gets exported to excel sheet.
    It is working fine with a single table. The problem now is that i am unable to do the same with 2 tables.
    Because both the tables have same number of columns & column names.
    Below are 2 tables with column names:
    Table-1 (MONTHLY_PART_1)
    Table-2 (MONTHLY_PART_2)
    SL_NO
    SL_NO
    COMP
    COMP
    DUE_DATE
    DUE_DATE
    U-1
    U-1
    U-2
    U-2
    U-4
    U-4
    U-20
    U-20
    U-25
    U-25
    Since both the tables have same column names, I'm getting the following error :
    Error 402 at line 103, column 4
      alias required in SELECT list of cursor to avoid duplicate column names.
    So How can i export the data to excel which has 2 tables with same number of columns & column names?
    Should i paste the code? Should i post this query in 'SQL and PL/SQL' Forum?
    Help me with this please.
    Thank You.

    You'll have to *alias* your columns, not prefix it with the table names:
    $[CHE_TEST@asterix1_impl] r
      1  declare
      2    cursor cData is
      3      with data as (
      4        select 1 id, 'test1' val1, 'a' val2 from dual
      5        union all
      6        select 1 id, '1test' val1, 'b' val2 from dual
      7        union all
      8        select 2 id, 'test2' val1, 'a' val2 from dual
      9        union all
    10        select 2 id, '2test' val1, 'b' val2 from dual
    11      )
    12      select a.id, b.id, a.val1, b.val1, a.val2, b.val2
    13      from data a, data b
    14      where a.id = b.id
    15      and a.val2 = 'a'
    16      and b.val2 = 'b';
    17  begin
    18    for rData in cData loop
    19      null;
    20    end loop;
    21* end;
      for rData in cData loop
    ERROR at line 18:
    ORA-06550: line 18, column 3:
    PLS-00402: alias required in SELECT list of cursor to avoid duplicate column names
    ORA-06550: line 18, column 3:
    PL/SQL: Statement ignored
    $[CHE_TEST@asterix1_impl] r
      1  declare
      2    cursor cData is
      3      with data as (
      4        select 1 id, 'test1' val1, 'a' val2 from dual
      5        union all
      6        select 1 id, '1test' val1, 'b' val2 from dual
      7        union all
      8        select 2 id, 'test2' val1, 'a' val2 from dual
      9        union all
    10        select 2 id, '2test' val1, 'b' val2 from dual
    11      )
    12      select a.id a_id, b.id b_id, a.val1 a_val1, b.val1 b_val1, a.val2 a_val2, b.val2 b_val2
    13      from data a, data b
    14      where a.id = b.id
    15      and a.val2 = 'a'
    16      and b.val2 = 'b';
    17  begin
    18    for rData in cData loop
    19      null;
    20    end loop;
    21* end;
    PL/SQL procedure successfully completed.
    cheers

  • Creating Multiple Files with different name at Receiver side

    Gurus -
    Can anybd tell me how to generate multiple files at the Receiver side in the given target directory with different file names?
    One source message will contain number "N" using which we have to generate files "N" number of times at the Receiver side.
    Kindly help.

    hi,
    are you following this blog?
    provided you have SP>14 and no IDOC/HTTP involved.
    and have you got the error you mentioned when testing with sample payload?
    from where did you take the payload? if is from SXMB_MONI make sure you dont have <MESSAGE> tags in the payload,generally systems adds <MESSAGE> tags when you do multi mapping.
    get the payload from SXMB_MONI right click ->view source payload(this is raw data) and test it.
    it should be ok now.
    and refer my discussion in the thread ,as I got he same error.
    Split mapping created no messages -Mluti Mapping

  • HT204053 i RECENTLY PURCHASED ANOTHER IPHONE.  MY INTERNET IS NOT WORKING.  I JUST CREATED AN APPLE ID.  WHAT'S NEXT?  I NOW HAVE TWO DIFFERENT ACCOUNTS WITH DIFFERENT USER NAMES.  HOW CAN I USE ONLY ONE ACCOUNT FOR ITUNES, ICLOUD APPLE ID ETC???

    I RECENTLY PURCHASED ANOTHER IPHONE.  MY INTERNET IS NOT WORKING.  I JUST CREATED AN APPLE ID.  WHAT'S NEXT?  I NOW HAVE TWO DIFFERENT ACCOUNTS WITH DIFFERENT USER NAMES.  HOW CAN I USE ONLY ONE ACCOUNT FOR ITUNES, ICLOUD APPLE ID ETC???

    Welcome to the Apple community.
    iTunes and iCloud and different accounts, you will need to delete both accounts from your device before adding the new details in their place.
    For iCloud go to settings > iCloud, scroll down and hit the delete button. You can then sign back in using your correct details. For iTunes go to settings >store, tap your account ID and then sign out, you can then sign back in using your correct Apple ID.

  • How to create a table with directory which is on different machine

    Hi All,
    I have two servers one is db server db1 and another is app server app1
    I will get files from customer into app1 server in the path d:\files\incoming
    I want to create a table with directory (when I create that it will be mapped to db1) which maps to app1\d\files\incoming,
    please let me know how to achieve this,

    NSK2KSN wrote:
    Hi All,
    I have two servers one is db server db1 and another is app server app1
    I will get files from customer into app1 server in the path d:\files\incoming
    I want to create a table with directory (when I create that it will be mapped to db1) which maps to app1\d\files\incoming,
    please let me know how to achieve this,This is nothing to do with SQL or PL/SQL as such.
    The answer lies in the remit of your Windows administrator to create an alias or link that points
    from your db server to your app server.
    Once that is done, you can refer to the directory as if it was a local one situated on the db server, as normal.
    Edited by: Paul Horth on Feb 21, 2013 10:13 AM
    Changed Unix to Windows when I noticed the direction of the slashes.

  • How to create a table with events in smartforms?

    How to create a table with events view in smartforms?
    It doesn't like general table with header, main area and footer.
    for example:
    in smartforms: LE_SHP_DELNOTE
    table name is TABLEITEM(Delivery items table)

    Vel wrote:
    I am creating XML file using DBMS_XMLGEN package. This XML file will contain data from two different database tables. So I am creating temporary table in the PL/SQL procedure to have the data from these different tables in a single temporary table.
    Please find the below Dynamic SQL statements that i'm using for create the temp table and inserting the data into it.
    Before insert the V_NAME filed, i will be appending a VARCHAR field to the original data.
    EXECUTE IMMEDIATE 'CREATE TABLE TEMP_TABLE (UNIQUE_KEY NUMBER , FILE_NAME VARCHAR2(1000), LAST_DATE DATE)';
    EXECUTE IMMEDIATE 'INSERT INTO TEMP_TABLE values (SEQUENCE.nextval,:1,:2)' USING V_NAME,vLastDate;What exactly i need is to eliminate the INSERT portion of it,Since i have to insert more 90,000 rows into it. Is there way to have the temp table created with data in it along with the sequence value as well.
    I'm using Oracle 10.2.0.4 version.
    Edited by: 903948 on Dec 22, 2011 10:58 PMWhat you need to do to eliminate the INSERT statement is to -- as already suggested by others - eliminate the temporary table. You don't need it. It is just necessary overhead. Please explain why you (apparently) believe that the suggestion of a view will not meet your requirements.

  • Table with varying number of columns

    Hello experts,
    my issue:
    I need to print a table with varying number of columns. Depending on if all cells of a certain column are initial the
    whole column should disappear. Hiding is not enough.
    If this columns is in the middle of the table the following columns should move left to fill the gap.
    my approach: (maybe there is an easier one)
    There are 4 different possible situations. My approach was to create 4 different tables with different amount of
    columns. In the interface I fill the table that is really needed from the source table data and fill a flag that characteristics
    the situation, possible values (1,2,3,4).
    In the form I'd like to print the appropriate table depending on the situations.
    my problem:
    How to place all 4 possible tables lying upon each other in the form and print only the needed one depending on the flag value?
    my question:
    Is my approach ok? Or is there an easier one?
    If it is ok. How can I solve the problem regarding printing the right table.
    Thanks in advance!
    Heinz

    Hi Heinz,
    You can handle it with FormCalc Script at initialization.
    Suppose you have a table with name TABLE having a header HEADER and data row DATA:
    TABLE-->HEADER(Cell1...Cell2...Cell3...Cell4)
              --->DATA(Cell1...Cell2...Cell3...Cell4)
    Suppose you want to hide Cell3 for null values, then write below code at initialization of DATA:
    if(DATA[*].Cell3.rawValue eq null)
    then
    DATA[*].Cell3.presence = "hidden"
    HEADER.Cell3.presence = "hidden"
    else
    DATA[*].Cell3.presence = "visible"
    HEADER.Cell3.presence = "visible"
    endif
    Hope it would help.
    Regards,
    Vaibhav

  • How can I check if there is a table with the given name ?

    I'm using 8i and 9i.
    Could anybody teach me how to check if there is a table with a certain name in SQLPLUS without using SELECT
    statement ?
    I want to use the following logical procedure.
    if exists "table_to_be_deleted" then drop table "table_to_be_deleted"
    Or, is there any system table that I can check the names of tables like
    count = select "table_to_be_deleted" from "an_oracle_system_table"
    if ( count != 0 ) then drop table "table_to_be_deleted"
    Thanks,
    John

    Just create it, but be aware that DDLs can't be executed directly from Pl/Sql, so you'll have to use dynamic Sql, e.g. :
    SQL> create table test(a number);
    Table created.
    SQL> begin
      2  drop table test;
      3  exception
      4  when others then
      5  null;
      6  end;
    SQL> /
    drop table test;
    ERROR at line 2:
    ORA-06550: line 2, column 1:
    PLS-00103: Encountered the symbol "DROP" when expecting one of the following:
    begin case declare exit for goto if loop mod null pragma
    raise return select update while with <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> <<
    close current delete fetch lock insert open rollback
    savepoint set sql execute commit forall merge pipe
    SQL> ed
    Wrote file afiedt.buf
      1  begin
      2  execute immediate 'drop table test';
      3  exception
      4  when others then
      5  null;
      6* end;
    SQL> /
    PL/SQL procedure successfully completed.
    SQL>Now the table does not exist anymore, but further executions will not generate errors, due to the exception handler :
    SQL> desc test
    ERROR:
    ORA-04043: object test does not exist
    SQL> /
    PL/SQL procedure successfully completed.
    SQL>

Maybe you are looking for

  • Non-durable Topic subscription with ClientID in a cluster environment

    forgive me for asking this, i spent the entire day trying this out in my pc but still not able to get the exact result. If i deploy an MDB on jms2 server with the following configuration in a cluster enviroment (jms1[masterbroker] <--> jms2) under Su

  • Value update incorrect

    I am doing this: rs.updateDouble("Amount",10.23); rs.updateRow(); but the value at my MS SQL Server become: 10.2299957275391 rather than 10.23. Please help. Regards, MingMan

  • Help!Electronic noises,server issues,console messages,ethernet -PowerPC G4

    I've been searching the internet as well as the Console and Activity Monitor for answers to this scenario, and it looks as though there is some kind of relationship between recent strange sounds I have been hearing over my speakers and server issues

  • Duplicated Requirement at MD04

    Hallo, I have an issue related with a duplicated requirement for a Sales Order. Our system is customized in order of working with the next process [Make-to-Order strategy]: Sales Order--> Planned Order --> Process Order --> Outbound Delivery --> Bill

  • DVCPROHDAudio.plugin Error - Sound Randomly Works

    I get the following error in the console: Error loading /Library/Audio/Plug-Ins/HAL/DVCPROHDAudio.plugin/Contents/MacOS/DVCPROHDAudio: dlopen(/Library/Audio/Plug-Ins/HAL/DVCPROHDAudio.plugin/Contents/MacOS/DVCPROHD Audio, 262): no suitable image foun