MDF master data file, only one master data file in a database
NDF data file, a database can have multiple secondary data files
LDF database log file
To create a database using SQL statements
----------------------------------------------------------------------------------------------------------- -----------------
Create a database of data files and a log file
1 UseMaster--point to the currently used database2 GO --flags for batch processing3 CREATE DATABASEE_market--Create a E_market database4 on PRIMARY --Primary file Group5 (6NAME= 'E_market_data',--Master file logical filename7FILENAME= 'C:\project\E_Market_data.mdf',--Master file physical filename8SIZE=5MB,--primary file Initial size9MAXSIZE=100MB,--maximum number of primary file growthTenFileGrowth= the% --the growth rate of the master file One ) A LOG on --log File - ( -NAME= 'E_market_log',--log file logical filename theFILENAME= 'H:\project\E_Market_log.ldf',--Log Physical file name -SIZE=5MB,--log file Initial size -FileGrowth= 0 --auto Grow not enabled -)
----------------------------------------------------------------------------------------------------------- ------------------Create multiple data files and multiple log files
1 UseMaster2 GO3 CREATE DATABASEE_market4 on PRIMARY --Primary file Group5 (6NAME= 'E_market_data',7FILENAME= 'C:\project\E_Market_data.mdf',8SIZE=10MB,9FileGrowth= Ten%,TenMAXSIZE=500M One),--End of first filegroup AFILEGROUP FG--a secondary filegroup was created - ( -NAME= 'Fg_e_market_data', theFILENAME= 'C:\PROJECT\FG_E_MARKET_DATA.NDF', -SIZE=10MB, -FileGrowth= 0 - ) + -----Log files do not belong to any filegroup - LOG on + ( ANAME= 'E_market_log', atFILENAME= 'C:\project\E_Market_log.ldf', -SIZE=5MB, -FileGrowth= 0 - ) -,----specific description of log 2 - ( inNAME= 'E_market_log1', -Fliename= 'C:\project\E_Market_log1.ldf', toSIZE=5MB, +FileGrowth= 0 -)
----------------------------------------------------------------------------------------------------------- ------------------to add filegroups and data files to an existing database1. Add filegroups and data files under Views add filegroups and files using SQL statements
1 UseE_market2 3----Add Filegroup FG14 ALTER DATABASEE_marketADDFILEGROUP FG15 GO6 7 ----add a data file for the newly created filegroup FG18 ALTER DATABASEE_marketADD FILE 9 (TenNAME= 'Fg1_e_market_data', OneFILENAME= 'C:\PROJECT\FG1_E_MARKET_DATA.NDF', ASIZE=5MB, -FileGrowth=Ten% -) toFILEGROUP FG1--store in the fg! the GO - ----Set the FG1 filegroup as the default file group - ALTERDATABASEE_market -MODIFY FILEGROUP FG1DEFAULT
---delete a database
1. Use view to delete database
2. Delete database using SQL statement
----to delete a e_market database
1 Use master--point to the current Operations database 2 drop database E_market--delete the databases 3 GO
----Check if the database you want to delete exists
1 IF EXISTS (SELECT * from sysdatabase WHERE name = ' E_market ') 2 DROP DATABASE e_market3 GO
SQL Server Learning-database management