I read xsd and xml file in DataSet
, now I want create db from this DataSet
foreach (DataTable dt in temp.Tables) {
foreach (DataColumn dc in dt.Columns) {
//example for one column
SqlCommand createtable = new SqlCommand(
"create table " + dt.TableName + " ("
+ dc.ColumnName + " varchar(max))", conn);
createtable.ExecuteNonQuery();
}
}
But I have some problem, when I create db table I need column type and size from XSD (in example use varchar(max)
). How to fix this?
For example in xsd I have
<xs:restriction base="xs:string">
<xs:maxLength value="36"/>
<xs:minLength value="1"/>
</xs:restriction>
or
<xs:restriction base="xs:string">
<xs:maxLength value="40"/>
</xs:restriction>
or
<xs:restriction base="xs:decimal">
<xs:totalDigits value="19"/>
<xs:fractionDigits value="2"/>
</xs:restriction>
In the end I need script to create db tables with size of columns (like in xsd)
UPD: Maybe use XmlSchemaSet
to parse XSD?
In SQL Server Object Explorer, under the SQL Server node, expand your connected server instance. Right-click the Databases node and select Add New Database. Rename the new database to TradeDev. Right-click the Trade database in SQL Server Object Explorer, and select Schema Compare.
Click in the text area and type a Create Database statement using the following Transact-SQL code as a guide: CREATE DATABASE MyDatabase ON (FILENAME = 'c:\data files\my_data. mdf'), (FILENAME = ' c:\data files\my_data.
use XSD2DB
XSD2DB is a command line tool written in C#
, that will read a Microsoft ADO.NET compatible DataSet Schema File (XSD)
and generate a database.
link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With