[RESOLVED] How to create a number of dataBase dataTables
Hi
I need to create a number of tables in my sql server database. For a asp.net proyect.
Exactly one for each letter of the alphabet.
I started of creating , the first table with the visual studio sql database designer. But thought it would be to much work to do it that way.
I now this is a newbie question, but how can I create them from sql code?
Any links to pages , beginner pages which could help?
Thanks
Re: How to create a number of dataBase dataTables
Question: How many fields will be in each table? Will it be all the same field names and field types and field lengths?
Re: How to create a number of dataBase dataTables
Thanks,
I managed to do it in the end:
Code:
string _conn = "Data Source=.\\SQLEXPRESS;Initial Catalog=httpBaseDatos;Integrated Security=True;Pooling=False";
SqlConnection myConn = new SqlConnection(_conn);
SqlCommand myCommand = myConn.CreateCommand();
myCommand.CommandType = CommandType.Text;
char mychar;
for (int i = 65; i <= 90; i++)
{
try
{
mychar = (char)i;
myCommand.CommandText = "CREATE TABLE tabla_letra_" + mychar + "(" +
"_id int NOT NULL IDENTITY(1,1)," +
"letra varchar(5) NOT NULL, nombre varchar(20)," +
" provincia varchar(20), cv varchar(max),PRIMARY KEY(_id))";
myConn.Open();
myCommand.ExecuteNonQuery();
myConn.Close();
}
catch
{
}
}
Re: How to create a number of dataBase dataTables
If you consider this resolved, would you please pull down the Thread Tools menu and click the Mark Thread Resolved menu item? That will let everyone know that you have your answer.
Thank you. :)