How to make script that make some things on SQL Server 2008?
I need t开发者_运维问答o make some things on SQL Server 2008 and I need it on any file or script that I can take it on another computer that has SQL Server 2008
I need this:
to add field
F1 (nvarchar)
andF2 (bit)
to tableMyTable1
and to make new table
MyTable2
to delete
Table3
How to combine to one script file ?
thanks in advance
You can try something like this, which will work in SQL Server Management Studio:
ALTER TABLE dbo.MyTable1
ADD F1 NVARCHAR(100)
ALTER TABLE dbo.MyTable1
ADD F2 BIT
GO
CREATE TABLE dbo.MyTable2(... define some columns here.......)
GO
DROP TABLE dbo.Table3
GO
This uses the GO
separator which is a keyword for SSMS - but it's not a valid SQL keyword (e.g. you cannot run this from code using a SQL Server client library).
ALTER TABLE MyTable1 ADD COLUMN F1 NVARCHAR
ALTER TABLE MyTable1 ADD COLUMN F2 BIT
GO
CREATE TABLE MyTable2 (
-- whatever
)
GO
DROP TABLE Table3
GO
Then put that in a file and run it with SQLCMD or open it in SSMS.
精彩评论