SQL Server 2008 delete all tables under special schema

后端 未结 13 1640
广开言路
广开言路 2021-01-30 01:02

Hello I would like to know is is possible to drop all tables in database what was created under custom schema for example DBO1...with one sql query or special script.

T

13条回答
  •  青春惊慌失措
    2021-01-30 01:32

    Also building on @Kevo's answer, I added the following while loop for an issue I was having with TSQL Print statement. A message string can be up to 8,000 characters long. If greater than 8,000 the print statement will truncate any remaining characters.

    DECLARE @SqlLength int
          , @SqlPosition int = 1
          , @printMaxLength int = 8000
    
    SET @SqlLength = LEN(@Sql)
    
    WHILE (@SqlLength) > @printMaxLength
    BEGIN
        PRINT SUBSTRING(@Sql, @SqlPosition, @printMaxLength)
        SET @SqlLength = @SqlLength - @printMaxLength
        SET @SqlPosition = @SqlPosition + @printMaxLength
    END
    IF (@SqlLength) < @printMaxLength AND (@SqlLength) > 0
    BEGIN
        PRINT SUBSTRING(@Sql, @SqlPosition, @printMaxLength)
    END
    

提交回复
热议问题