I want to generate all scripts in my database. As you know, clicking "Generate Scripts", it outputs all tables, all stored procedures etc. with CREATE
statements.
How can I get an ALTER
statement for recently changed tables and CREATE
statement for recently added tables, at the same time?
As an example, A, B, C, D tables were created before. Then I add a new table as E and I changed a column name in C. When I click "Generate Scripts", it must output:
IF NOT EXISTS ....
CREATE TABLE A
....
IF NOT EXISTS ....
CREATE TABLE B
....
IF NOT EXISTS ....
CREATE TABLE C
....
IF NOT EXISTS ....
CREATE TABLE D
....
IF NOT EXISTS ....
CREATE TABLE E
....
ALTER TABLE C
MODIFY COLUMN XX...
like this.
Generate Scripts will just give you the create statements for the various objects in your database. It sounds like you're looking for a source control system, which would be able to generate CREATE/ALTER statements depending on changes from what is in source control.
Use SSMS to generate your scripts into a new query window, then in SSMS in that new query window do a find and replace using a RegEx search.
So if your script contains Functions click Ctrl+H then:
Search item: (create.*function)
Replacement item: create or alter function
Then replace as needed
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.