|
-
Feb 27th, 2007, 10:40 AM
#1
Thread Starter
Hyperactive Member
[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
-
Feb 27th, 2007, 10:52 AM
#2
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?
-
Feb 28th, 2007, 08:04 AM
#3
Thread Starter
Hyperactive Member
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
{
}
}
Last edited by Hack; Feb 28th, 2007 at 08:35 AM.
-
Feb 28th, 2007, 08:36 AM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|