SQL statements create folders, determine folders, create databases, tables,

Source: Internet
Author: User
Code Use Master;
Go
If Exists ( Select   *   From SYS. Databases Where Name =   ' Testdb ' )
Drop   Database Testdb

-- Create a folder
Exec Sp_configure ' Show advanced options ' , 1
Go
Reconfigure
Go
Exec Sp_configure ' Xp_mongoshell ' , 1
Reconfigure
Go
Exec Xp_mongoshell ' Mkdir D: \ aaa '   -- Call the doscommand to create a project folder
-- Exec xp_cmdshell 'RD D: \ new/S/Q' -- delete a folder
-- Create a database
/* *
Note:
1. Filename Path;
2. initialize the database size and growth mode
* */
Execute ( ' Create Database testdb
On
(Name = testdb_dat,
Filename = '' D: \ AAA \ testdb. MDF '' ,
Size = 500,
Maxsize = unlimited,
Filegrowth = 100)
Log On
(Name = testdb_log,
Filename = '' D: \ AAA \ testdb. LDF '' ,
Size = 500,
Maxsize = unlimited,
Filegrowth = 100) '
);

The following is an SQL statement used to determine whether a folder exists.

Xp_fileexist: checks to see if a given file exists or not. it returns three columns with a value of 1 (yes) or 0 (no): file exists, file is a directory and parent directory exists.

Code Create   Table # TMP ( [ File exists ]   Bit , [ File is a directory ]   Bit , [ Parent directory exists ]   Bit )
 
  Insert   Into # TMP ( [ File exists ] , [ File is a directory ] , [ Parent directory exists ] )
 
  Exec Master. DBO. xp_fileexist ' D: \ aaa '
 
  Select   *   From # TMP
 
  Drop   Table # TMP

 

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.