1 package SQL::Translator::Producer::SQLServer;
7 $DEBUG = 1 unless defined $DEBUG;
9 use SQL::Translator::Schema::Constants;
10 use SQL::Translator::Utils qw(debug header_comment);
11 use SQL::Translator::Generator::DDL::SQLServer;
14 my $translator = shift;
15 my $future = SQL::Translator::Generator::DDL::SQLServer->new(
16 add_comments => !$translator->no_comments,
17 add_drop_tables => $translator->add_drop_table,
20 my $schema = $translator->schema;
22 my $output = $future->header_comments
23 . $future->drop_tables($schema);
25 for my $table ( grep { $_->name } $schema->get_tables ) {
26 $output .= join( "\n\n",
27 $future->table($table),
28 $future->unique_constraints_multiple($table),
29 $future->indices($table),
33 my @foreign_constraints = $future->foreign_key_constraints($schema);
34 $output .= join ("\n", '', @foreign_constraints) if @foreign_constraints;
43 =head1 SQLServer Create Table Syntax
50 SQL::Translator::Producer::SQLServer - MS SQLServer producer for SQL::Translator
56 my $t = SQL::Translator->new( parser => '...', producer => 'SQLServer' );
61 B<WARNING>B This is still fairly early code, basically a hacked version of the
62 Sybase Producer (thanks Sam, Paul and Ken for doing the real work ;-)
64 =head1 Extra Attributes
70 List of values for an enum field.
76 * !! Write some tests !!
77 * Reserved words list needs updating to SQLServer.
78 * Triggers, Procedures and Views DO NOT WORK
81 # Text of view is already a 'create view' statement so no need to
83 foreach ( $schema->get_views ) {
84 my $name = $_->name();
86 $output .= "--\n-- View: $name\n--\n\n" unless $no_comments;
89 $output .= "$text\nGO\n";
92 # Text of procedure already has the 'create procedure' stuff
93 # so there is no need to do anything fancy. However, we should
94 # think about doing fancy stuff with granting permissions and
96 foreach ( $schema->get_procedures ) {
97 my $name = $_->name();
99 $output .= "--\n-- Procedure: $name\n--\n\n" unless $no_comments;
100 my $text = $_->sql();
102 $output .= "$text\nGO\n";
111 Mark Addison E<lt>grommit@users.sourceforge.netE<gt> - Bulk of code from
112 Sybase producer, I just tweaked it for SQLServer. Thanks.