Como crear 10 o 100 tablas en SQL Server

   declare @count int=1

  declare @sql varchar(100)


  --select @sql

  WHILE (@count =<10)

  BEGIN

set @sql=CONCAT('create table',SPACE(1),'T',@count,

  '(c1 int)')

execute (@sql)

set @count=@count+1

  END

El código crea tablas t1, t2, t3 hasta el 10. Si uno desea crear más tablas cambia el 10 por el número de tablas que desea.

Básicamente se tiene un contador que se llama count. Y ese contador le aumenta el nombre de manera dinámica. El comando CONCAT concatena la sentencia create table y usando la variable count.



Comentarios

  1. Este comentario ha sido eliminado por el autor.

    ResponderEliminar
  2. A hook maker for essay is an invaluable tool for captivating your readers right from the start. It provides the perfect opening line or paragraph that grabs attention and sets the tone for your entire essay. With a hook maker, you can create compelling introductions that leave a lasting impression, making your essay stand out and engage your audience from the very beginning.

    ResponderEliminar

Publicar un comentario

Entradas populares de este blog

The Deep Sea: una web interactiva para explorar las profundidades el mar y descubrir las extrañas criaturas que viven en él

Detectar el usuario de Windows utilizando C#

Lo nuevo de SQL Server 2008 respecto a SQL Server 2005