I am creating a windows application using VB.Net and this application will take a SQl create .sql file as a parameter and will return all fields and their data types inside in a list or array.
Example:
USE [MyDB] GO /****** Object: Table [dbo].[User] Script Date: 07/07/2009 10:16:48 ******/
SET
ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[User]( [UserId] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [MiddleName]
[varchar](50) COLLATE SQL_Latin1_General_CP1_CI_A
Should Return:
UserId int, FirstName string, MiddleName string
I want to do this by any way, pure vb.net code or using RegEx.
Anyone knows the fastest way to finish this?
First, what flavor of SQL are you using? Second, the syntax for
CREATE TABLEcan be fairly “detailed”. Are you dealing with a smaller subset of the general syntax that might make approaching this problem simpler?But rather than trying to parse the statement, the fastest way might be having a trash database that you can execute the
CREATE TABLEstatement on, and then extracting the column names and types via(I am assuming SQL Server here.)
Thusly,
Sorry that it’s in C#. I am not fluent enough with VB to write approximately correct code without a compiler at my fingertips.