SQL Server Management studio manager is used with caution sometimes. Writing script modifications is king.

Source: Internet
Author: User
Tags sql server management sql server management studio

The SQL Server Management studio manager is really cheap. It was accidentally discovered today by using the script tracker.
I modified the rowflag field int to bit for a field type.

The SMS manager did this.

For example, table name: ABC
1. Create a temporary table based on the field structure modified by ABC and name it tmp_abc.

It does this.

CREATE TABLE dbo.Tmp_ABC(    ID uniqueidentifier NOT NULL,    ServerIP varchar(20) NULL,    AccountName nvarchar(50) NULL,    StaffID int NULL,    StaffName nvarchar(50) NULL,    GroupID int NULL,    GroupName nvarchar(200) NULL,    Remark nvarchar(MAX) NULL,    OperatorName nvarchar(50) NULL,    RecFlag tinyint NULL,    OperatorTime datetime NULL,    RowFlag bit NULL)  ON [PRIMARY]TEXTIMAGE_ON [PRIMARY]

2.Insert all data of ABC into from tmp_abc table

It does this (it's a little scary)

IF EXISTS(SELECT * FROM dbo.ABC)EXEC('INSERT INTO dbo.Tmp_ABC(ID, ServerIP, AccountName, StaffID, StaffName, GroupID, GroupName, Remark, OperatorName, RecFlag, OperatorTime, RowFlag)SELECT ID, ServerIP, AccountName, StaffID, StaffName, GroupID, GroupName, Remark, OperatorName, RecFlag, OperatorTime, CONVERT(bit, RowFlag) FROM dbo.ABC WITH (HOLDLOCK TABLOCKX)')

3. Delete ABC and change the tmp_abc name to ABC.

It does this.

 

DROP TABLE dbo.ABCEXECUTE 

sp_rename N'dbo.Tmp_ABC', N'ABC', 'OBJECT'

 

4. Get all ABC attributes, foreign keys, descriptions, and relationships to the tmp_abc temporary table.

It does this.

ALTER TABLE dbo.ABC ADD CONSTRAINT    PK_AccountRec PRIMARY KEY CLUSTERED     (    ID    ) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

And so on.

If this table requires a lot of data, it will not be a tragedy ..

I'm so convinced of Microsoft's software engineer. It's a good task of stealing.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.