Today we’re going to be reviewing four ways to get rid of a database from a SQL Server
• Method #1 – Drop via GUI
• Method #2 – Drop via TSQL
• Method #3 – Detach via GUI
• Method #4 – Detach via TSQL
IF OBJECT_ID('dbo.numbers') IS NOT NULL DROP TABLE dbo.numbers;
GO
SELECT TOP 123 N=IDENTITY(INT, 1, 1), NULL AS somenum
INTO dbo.Numbers
FROM master.dbo.syscolumns a CROSS JOIN master.dbo.syscolumns b;
ALTER TABLE dbo.Numbers ADD CONSTRAINT NBR_pk PRIMARY KEY(N);
GO
-- declare the variables
DECLARE @batchsize BIGINT = 500;
DECLARE @currID BIGINT = 0;
DECLARE @maxID BIGINT;
-- set the loop limit
SELECT @maxID = MAX(N) FROM dbo.numbers;
-- loop over the inside query using the loop limiter to control, and
-- the batch size to control the size of "bites" we take out of the target
WHILE @currid < @maxID
BEGIN
UPDATE dbo.numbers
SET somenum = RAND()*100
WHERE N > @currID AND N <= (@currID + @batchsize);
SET @currID = @currID + @batchsize;
END
GO
-- prove it worked
SELECT TOP 5000 * FROM dbo.Numbers WHERE n IN (1,12,123,1234,12345,123456);
GO
$netadapter = Get-NetAdapter -Name Ethernet1 $netadapter | Set-NetIPInterface -DHCP Disabled $netadapter | New-NetIPAddress -AddressFamily IPv4 -IPAddress 10.0.1.110 -PrefixLength 24 -Type Unicast -DefaultGateway 10.0.1.100 Set-DnsClientServerAddress -InterfaceAlias Ethernet1 -ServerAddresses 10.0.1.100
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False Rename-Computer "MemberServer" add-computer -Credential contoso\ironman -DomainName contoso.com Restart-Computer
$netadapter = Get-NetAdapter -Name Ethernet1 $netadapter | Set-NetIPInterface -DHCP Disabled $netadapter | New-NetIPAddress -AddressFamily IPv4 -IPAddress 10.0.1.110 -PrefixLength 24 -Type Unicast -DefaultGateway 10.0.1.100 Set-DnsClientServerAddress -InterfaceAlias Ethernet1 -ServerAddresses 10.0.1.100 Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False Rename-Computer "MemberServer" add-computer -Credential contoso\ironman -DomainName contoso.com Restart-Computer
$netadapter = Get-NetAdapter -Name Ethernet1 $netadapter | Set-NetIPInterface -DHCP Disabled $netadapter | New-NetIPAddress -AddressFamily IPv4 -IPAddress 10.0.1.100 -PrefixLength 24 -Type Unicast -DefaultGateway 10.0.1.100 Set-DnsClientServerAddress -InterfaceAlias Ethernet1 -ServerAddresses 10.0.1.100 Rename-Computer "pdc" Restart-Computer
Install-windowsfeature -name AD-Domain-Services -IncludeManagementTools Import-Module ADDSDeployment Install-ADDSForest -domainname "contoso.com" -DomainMode 6 -DomainNetbiosName "CONTOSO" -ForestMode 6 -InstallDNS -Force -SafeModeAdministratorPassword (ConvertTo-SecureString -AsPlainText "password" -Force)
Cannot connect to WMI provider. You do not have permission or the server is unreachable. Noe that you can only manage SQL Server 2005 and later servers with SQL Server Configuration Manager. Invalid Namespace (0x8004100e)
Microsoft has moved the documentation for this product online in order to provide the most current information to our customers. See the Microsoft Developer Network (MSDN) Resources page (http://go.microsoft.com/fwlink/?LinkId=299888) for more information.