简体   繁体   中英

Scripts generated by SQL Server 2012 can not run again?

I have a problem when generating scripts from a database. It's quite simple, but i don't know how to fix it. The Stored Procedure objects is created before the Table objects. Here is all scripts:

 USE [ComicSellerManagement]
GO
/****** Object:  StoredProcedure [dbo].[sp_AddingComicGenre]    Script Date: 3/3/2016 3:39:38 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[sp_AddingComicGenre]
@name nvarchar(50),
@info nvarchar(max)
as begin
    insert into COMIC_GENRE values (@name, @info)
end
GO
/****** Object:  StoredProcedure [dbo].[sp_DeletingComicGenre]    Script Date: 3/3/2016 3:39:38 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[sp_DeletingComicGenre]
@id int
as begin
    delete from COMIC_GENRE where ID = @id
end
GO
/****** Object:  StoredProcedure [dbo].[sp_LoadingComicGenre]    Script Date: 3/3/2016 3:39:38 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[sp_LoadingComicGenre]
as begin
    select * from COMIC_GENRE
end
GO
/****** Object:  StoredProcedure [dbo].[sp_UpdatingComicGenre]    Script Date: 3/3/2016 3:39:38 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[sp_UpdatingComicGenre]
@id int,
@name nvarchar(50),
@info nvarchar(max)
as begin
    update COMIC_GENRE
    set GenreName = @name, Info = @info
    where ID = @id
end
GO
/****** Object:  Table [dbo].[COMIC]    Script Date: 3/3/2016 3:39:38 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[COMIC](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [Name] [nvarchar](50) NULL,
    [Genre] [int] NULL,
    [PublishYear] [int] NULL,
    [Publisher] [int] NULL,
    [Actor] [nvarchar](50) NULL,
    [Price] [money] NULL,
 CONSTRAINT [PK_COMIC] PRIMARY KEY CLUSTERED 
(
    [ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[COMIC_GENRE]    Script Date: 3/3/2016 3:39:38 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[COMIC_GENRE](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [GenreName] [nvarchar](50) NULL,
    [Info] [nvarchar](255) NULL,
 CONSTRAINT [PK_COMIC_GENRE] PRIMARY KEY CLUSTERED 
(
    [ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[COMIC_PUBLISHER]    Script Date: 3/3/2016 3:39:38 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[COMIC_PUBLISHER](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [PublisherName] [nvarchar](50) NULL,
    [Adress] [nvarchar](max) NULL,
    [PhoneContact] [char](11) NULL,
    [Discount] [float] NULL,
 CONSTRAINT [PK_COMIC_PUBLISHER] PRIMARY KEY CLUSTERED 
(
    [ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[COMIC_PUBLISHER] ADD  CONSTRAINT [DF_COMIC_PUBLISHER_Discount]  DEFAULT ((0)) FOR [Discount]
GO
ALTER TABLE [dbo].[COMIC]  WITH CHECK ADD  CONSTRAINT [FK_COMIC_COMIC_GENRE] FOREIGN KEY([Genre])
REFERENCES [dbo].[COMIC_GENRE] ([ID])
GO
ALTER TABLE [dbo].[COMIC] CHECK CONSTRAINT [FK_COMIC_COMIC_GENRE]
GO
ALTER TABLE [dbo].[COMIC]  WITH CHECK ADD  CONSTRAINT [FK_COMIC_COMIC_PUBLISHER] FOREIGN KEY([Publisher])
REFERENCES [dbo].[COMIC_PUBLISHER] ([ID])
GO
ALTER TABLE [dbo].[COMIC] CHECK CONSTRAINT [FK_COMIC_COMIC_PUBLISHER]
GO

I can not run this sql file to recover my database in any computer. Any suggestions for me to fix this?

  1. Try to change this option when generate your script -

在此处输入图片说明

  1. Another solution try to use dbForge Schema Comparison

  2. Use backup's

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM