Re: Data generator help!!

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On 15 Mar, 11:15, Simon Harvey <notha...@xxxxxxxxxxx> wrote:
Shum wrote:
Hi everybody!!
I really need help for my assignment... I want to make an application
in c# to populate the database (sql server 2005), so that later on we
can use that large amount of data for mining etc.
So any of you who knows how to go about implementing this thing are
free to reply...
I was thinking of doing it this way: first get the list of tables in
the database, then get the data type of the coulumn, if the data type
is int then generate a random number and insert that number into the
field.. move onto the next column.... and this is how all the tables
will be filled...
but i dont know how to get the data types of the columns etc....
Please do reply with your valuable suggestions... and ideas.

Thanks

For something like this you would need to use ado.net 2.0's metadata
functionality to examine the structure of the db and tables etc.

You can find out more about these features at:

http://msdn2.microsoft.com/en-us/library/ms379543(VS.80).aspx

Hope that helps

Kindest Regards

Simon- Hide quoted text -

- Show quoted text -

Alternatively you can do it through SQL:
The following will retrieve table columns and datatypes. I left the
index stuff in at the end as I agree with what Jon says below. You
could use it to identify what fields are key fields and then do god
knows what with that :)


DECLARE @TableName AS varchar(50)
SELECT @TableName ='results' -- <--- change this to your table!

-- databases
SELECT name, dbid FROM master..sysdatabases

-- Table and columns
SELECT SO.Name as SO_Name, SO.ID as SO_ID, SC.name as SC_Name,
SC.colid AS SC_ColID, ST.name AS ST_Name
FROM sysobjects SO JOIN syscolumns SC ON SO.id = SC.id INNER JOIN
systypes ST ON SC.xtype = ST.xtype
WHERE SO.name LIKE @TableName AND SO.xtype = 'U'

-- Table indexes
SELECT @TableName AS SO_Name, SI.indid AS SI_IndID, SI.name AS
SI_Name
FROM sysindexes SI
WHERE SI.id IN (select id FROM sysobjects WHERE name LIKE @TableName
AND xtype = 'U')
AND SI.name NOT LIKE '_WA_Sys%'

-- Table indexes with index keys
SELECT SO.name AS SO_Name, SI.name as SI_Name, SC.name AS SC_Name
FROM sysobjects SO INNER JOIN syscolumns SC ON SO.id = SC.id
INNER JOIN sysindexkeys SIK ON SIK.id = SO.id AND SC.colid =
SIK.colid
INNER JOIN sysindexes SI ON SI.id = SO.id AND SIK.indid = SI.indid
WHERE SO.name LIKE @TableName AND
SI.name NOT LIKE '_WA_Sys%'
--ORDER BY SI_Name

.



Relevant Pages

  • Re: Invalid column name true
    ... I've upsized an Access database ... If you perform a test on any integer-type number like this: ... In SQL Server, the BIT data type is always 1 for True and 0 for False. ...
    (microsoft.public.sqlserver.programming)
  • Re: Identifying stored procedure output columns
    ... but ur gonna have to Query the master database. ... INNER JOIN sys.schemas AS ssp ON ssp.schema_id = sp.schema_id ... As u might have guessed, I got these from Sql Server profiler, so you ... The profiler will catch all the relevant queries for u. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Access 95 Linked Tables with SQL Server 2000
    ... Try adding a timestamp field to a table and re-linking it. ... > The table were copied using DTS into SQL Server. ... > exception of the "Memo" data type, ... I cannot convert the front-end Access database until ...
    (microsoft.public.access.externaldata)
  • Re: Save mix data in database
    ... For reasons to lengthy to list here, putting BLOBs in the database (no matter how well SQL Server handles them) leads to too many other issues to justify their inclusion. ... and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ... What is the data type that I have to use when I want to save mix data in ...
    (microsoft.public.dotnet.framework.adonet)
  • Access 95 Linked Tables with SQL Server 2000
    ... I have a customer with an Access 95 database with linked ... I am running on Windows XP ... The table were copied using DTS into SQL Server. ... exception of the "Memo" data type, ...
    (microsoft.public.access.externaldata)