开发者

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:

  1. to add field F1 (nvarchar) and F2 (bit) to table MyTable1

  2. and to make new table MyTable2

  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜