Results 1 to 4 of 4

Thread: [RESOLVED] How to create a number of dataBase dataTables

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    Resolved [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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    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.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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
  •  



Click Here to Expand Forum to Full Width