Question : Sybase IQ generating distinct rows for dummy table

Hi,

I am trying to generate a table containing 25 columns and populate with some sample data. My aim is to get around 300k rows. I have generated the table with 300 distinct rows of sample data using powerdesigner. Does anybody know a nice way of blowing up this table to 300k rows without duplicating any of the data?? I tried using the STUFF function to take the last 2 digits of the ID and append to each column as follows: -

insert into test1 (C1)
select  stuff(C1,5,2,substring(convert(char, ID), length(convert(varchar, ID))-1,2))
from test1

But this method gives me duplicate values when I execute distinct count. Can some1 please help?

But this

Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
create table TEST1 (
   ID                   int                            null default autoincrement,
   C1                   char(6)                        null,
   C2                   char(6)                        null,
   C3                   char(6)                        null,
   C4                   char(6)                        null,
   C5                   char(6)                        null,
   C6                   char(6)                        null,
   C7                   char(6)                        null,
   C8                   char(6)                        null,
   C9                   char(6)                        null,
   C10                  char(6)                        null,
   C11                  char(6)                        null,
   C12                  char(6)                        null,
   C13                  char(6)                        null,
   C14                  char(6)                        null,
   C15                  char(6)                        null,
   C16                  char(6)                        null,
   C17                  char(6)                        null,
   C18                  char(6)                        null,
   C19                  char(6)                        null,
   C20                  char(6)                        null,
   C21                  char(6)                        null,
   C22                  char(6)                        null,
   C23                  char(6)                        null,
   C24                  char(6)                        null,
   C25                  char(6)                        null
);
 
insert into TEST1 (C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15, C16, C17, C18, C19, C20, C21, C22, C23, C24, C25) values ('H0A9HT', 'SGYO53', '27V8L2', '9EM508', ' MX12I', '5KP34L', '2S40AO', '2XIYW6', '0G5COU', 'T2QLOI', '4AQXA8', 'YIA80X', ' 6L8S2', 'IFR7NN', '8223LK', 'XHEKTW', '304GVR', 'W EMVT', '08G1JX', 'LT3CVB', 'GT38TX', '21DHHX', '5MKAWW', 'BNCISN', '1XDDJ2');
 
insert into TEST1 (C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15, C16, C17, C18, C19, C20, C21, C22, C23, C24, C25) values ('RU812M', 'M6 7WG', '3HUU4A', 'QU55G9', 'RJMNOY', 'WRDJMH', 'V8KGCT', 'UWONM1', '6C3O Q', '9Y  6G', '2H927L', 'TVUT U', 'R5RG0N', '9SUJ37', 'VTOO2Y', '4XPLMN', 'OLMPU8', 'WU6VLD', 'P70A3X', ' 12VPO', '0MI3TX', 'G2E1W2', 'NNBMI5', 'NOH5C9', '73MKPD');
Open in New Window Select All

Answer : Sybase IQ generating distinct rows for dummy table

You were not specific about what you wanted.  If I understand correctly, you want each value in each of the 26 columns to be unique across all 300,000 rows.

Using a RAND function will not guarantee any degree of uniqueness at all.  How could it?  They are random numbers.  It is a bit like rolling a die (one dice) six times and expecting to get a 1, 2, 3,, 4, 5, and 6.  It ain't likely to happen; roughly a 1 in 65 chance (precisely 5*4*3*2 in 6^5 chances).

You might want to examine your real requirements.  It would be very unusual for there to be 300,000 rows of 26 six character values and not have any duplicates.  Unless you are generating lottery tokens or something, real life will give you dupes much as you are getting with your random number generation.

If you really need each value to be unique, you will have to create each and every value explicitly.  26 columns cries out for each column to begin with a character of the alphabet.  The remaining 5 characters can be a zero-padded hex number.  You can adjust the starting offset for each one so they are not in total lockstep; you have plenty of room since 5 hex digits gives you just over 1 million possible values.

So what I would do is create the list of numbers from 1 to 300,000, then generate each column value from that by adding the column prefix (A-Z) and calculating a hex number from the ID (1-300000) and the offset for that column.

You can do this by creating a single column table with the IDs and a helper table with 26 columns of INT and the offset for each one.  You can then generate the entire target table in an INSERT/SELECT by joining your ID table with the Column Offset table and using an expression to generate each column value, e.g.

INSERT INTO TargetTable
SELECT ID,
               'A' + RIGHT(INTTOHEX(ID+CS.COL_A),5),
               'B'.........
FROM ID_Table,
           Column_Offset CS

Regards,
Bill
Random Solutions  
 
programming4us programming4us