-1

Yes, I know you can right click on table [Script Table as]->[CREATE To] and yes you can create your own procedure to generate 'CREATE TABLE' script. Question is, do SQL Server has any build-in procedure to auto generate 'CREATE TABLE' query?

UPDATE: I already have all table information, question is do sql-sever has any table that stores auto-generated scripts or does it have any procedure that you can run and that can give you create,insert,update scripts for table?

select '['+name+']'+' ['+type_name(system_type_id)+']'+
case when is_ansi_padded=1 then '('+cast(max_length as varchar)+')' else '' end + case when is_nullable=1 then ' NULL' else ' NOT NULL' end+',' 
  from sys.all_columns where object_id='132456'
order by column_id

1 Answers1

2

As far as I'm aware, SQL Server by itself does not have a generator for tables. You can use the OBJECT_DEFINITION() function for many database objects, but that does not work with all object types including tables.

SQL Server Management Studio does have a script generator. Indeed, SSMS has very powerful scripting tools, enabling you to script an entire database with all associated object and the data pretty easily with the Advanced options.

Bacon Bits
  • 30,782
  • 5
  • 59
  • 66