您的位置 首页 php

SQLServer创建数据库详解

2c3fc3ea-2926-40d9-a10a-70e0dc71ad77

1、创建数据库介绍

在创建数据库之前,需要先确定数据库的名称、所有者、大小、存储该数据库的文件和文件组。

数据库所有者:创建数据库的用户。一般情况下,大多数产品对象由数据库所有者拥有。

2、创建数据库注意事项

  • 创建数据库需要拥有CREATE DATABASE、CREATE ANY DATABASE或ALTER ANY DATABASE权限。
  • 创建数据库的用户将成为该数据库的所有者。
  • 针对一个SQL Server实例,最多可以创建32767个数据库。
  • 数据库名称必须遵循为标识符指定的规则。
  • 在创建新数据库同时,model数据库中的所有用户定义对象都会复制到新创建的数据库中。可以向model数据库中添加任何通用的对象(如表、视图、存储过程和数据类型),然后在创建的数据库可以将这些对象复制到新创建的数据库当中。

3、创建数据库的语法格式

语法格式如下:

       CREATE DATABASE database_name          [ ON            [ PRIMARY ] [ <filespec> [ ,...n ]            [ , <filegroup> [ ,...n ] ]          [ LOG ON { <filespec> [ ,...n ] } ]          ]          [ COLLATE collation_name ]      ][;]  

参数说明:

database_name :数据库名称。

ON :指定以显式定义方式指定存储数据库数据部分的数据文件。

PRIMARY :指定<filespec>列表中的主文件。在<filespec>项中的第一个文件将成为主文件。如果没有指定PRIMARY则默认第一个文件将成为数据库主文件。

LOG ON :指定存储数据库日志的日志文件。LOG ON后跟着以逗号分隔的用于定义日志文件的<filespec>项列表。不指定LOG ON,将自动创建一个日志文件,文件大小为该数据库的所有数据文件大小总和的1/4或512 KB,取两者之中的较大者。

COLLATE collation_name :指定数据库的默认排序规则。排序规则名称包括Windows排序规则、SQL排序规则名称。未指定排序规则,则将SQL Server实例的默认排序规则分配为数据库的排序规则。

<filespec>部分主要用于控制文件属性,语法格式如下:

       (          NAME = logical_file_name ,          FILENAME = 'os_file_name'            [ , SIZE = size [ KB | MB | GB | TB ] ]            [ , MAXSIZE = { max_size [ KB | MB | GB | TB ] | UNLIMITED } ]            [ , FILEGROWTH = growth_increment [ KB | MB | GB | TB | % ] ]      ) [ ,...n ]  

logical_file_name :指定文件的逻辑名称。logical_file_name必须在数据库中唯一,必须符合规定的标识符规则。

‘ os_file_name ‘ :指定操作系统(物理)文件名称。执行创建数据库语句前,指定文件路径必须存在。如果指定了UNC(通用命名约定)路径,则无法设置SIZE、MAXSIZE和FILEGROWTH参数。

size :指定文件的初始大小。未指定主文件指定size,数据库引擎将使用model数据库中的主文件的大小。如果指定了辅助数据文件或日志文件,但未指定该文件的size,则数据库引擎将以1 MB作为该文件的大小。

可以使用千字节(KB)、兆字节(MB)、千兆字节(GB)或兆兆字节(TB)后缀,默认单位为MB。

max_size :指定文件可增大到的最大值,可以使用KB、MB、GB和TB后缀,默认单位为MB。

UNLIMITED :指定文件可以增长到磁盘空间已满。在SQL Server中,指定为不限制增长的日志文件的最大值为2 TB,而数据文件的最大值为16 TB。

growth_increment :指定每次需要新空间时为文件添加的空间量。growth_increment值不能超过MAXSIZE设置值。该值可以使用MB、KB、GB、TB或百分比(%)为单位指定。默认值为MB。growth_increment值为0时表明自动增长被关闭,不允许增加空间。

如果未指定FILEGROWTH,则数据文件的默认值为1 MB,日志文件的默认增长比例为10%,并且最小值为64 KB。

<filegroup>部分主要用于控制文件组属性,语法格式如下:

     FILEGROUP filegroup_name [ DEFAULT ]          <filespec> [ ,...n ]  

filegroup_name :必须在数据库中唯一,不能是系统提供的名称PRIMARY和PRIMARY_LOG。

DEFAULT :指定文件组为数据库中的默认文件组。

4、 创建数据库示例

  1. 最简单的创建数据库示例

create database TestDB

会根据SQLServer默认设置(文件存储位置、文件增加大小等)创建数据库。

6544359b462f41d6ae1fbe1d189878ed

2.指定数据和事务日志文件的数据库示例

  IF DB_ID (N'TestDB') is not null  -- 判断数据库是否存在如果存在则先删除  DROP DATABASE TestDB   GO  CREATE DATABASE TestDB      ON      ( NAME = TestDB,-- 逻辑数据库文件名          FILENAME = 'D:\TestDB.mdf',          SIZE = 10,          MAXSIZE = 200,          FILEGROWTH = 5 )      LOG ON      ( NAME = TestDB_log,-- 逻辑数据库日志文件名          FILENAME = 'D:\TestDB_log.ldf',          SIZE = 5MB,          MAXSIZE = 50MB,          FILEGROWTH = 5MB ) ;  
e80b550cb3914865b04da125bf99c159

3.指定多个数据文件和事务日志文件示例

   USE master  GO     IF DB_ID (N'TestDB') is not null -- 判断数据库是否存在如果存在则先删除  DROP DATABASE TestDB   GO  CREATE DATABASE TestDB      ON      PRIMARY          (NAME = TestDB1,          FILENAME = 'd:\TestDB1.mdf',          SIZE = 100MB,          MAXSIZE = 200,          FILEGROWTH = 20),          ( NAME = TestDB2,          FILENAME = 'd:\TestDB2.ndf',          SIZE = 100MB,          MAXSIZE = 200,          FILEGROWTH = 20)      LOG ON        (NAME = TestDB_log1,          FILENAME = 'd:\TestDB_log1.ldf',          SIZE = 30MB,          MAXSIZE = 100,          FILEGROWTH = 10),        (NAME = TestDB_log2,          FILENAME = 'd:\TestDB_log2.ldf',          SIZE = 100MB,          MAXSIZE = 500,          FILEGROWTH = 50) ;  

f54134f7baf447358bbfd83a4350207f

4.创建具有文件组的数据库下面的语句将创建数据库Sales,该数据库具有以下文件组。

   USE master  GO     IF DB_ID (N'TestDB') is not null -- 判断数据库是否存在如果存在则先删除  DROP DATABASE TestDB   GO   CREATE DATABASE  TestDB      ON PRIMARY -- 数据库主文件      ( NAME = TestDB1,          FILENAME = 'd:\TestDB1.mdf',          SIZE = 20,          MAXSIZE = 100,          FILEGROWTH = 10% ),      ( NAME = TestDB2,          FILENAME = 'd:\TestDB2.ndf',          SIZE = 10,          MAXSIZE = 50,		  FILEGROWTH = 5% ),      FILEGROUP DBGroup1      ( NAME = TestDB3,          FILENAME = 'd:\TestDB3.ndf',          SIZE = 10,          MAXSIZE = 50,          FILEGROWTH = 5 ),      ( NAME = TestDB4,          FILENAME = 'd:\TestDB4.ndf',          SIZE = 10,          MAXSIZE = 50,          FILEGROWTH = 5 ),      FILEGROUP DBGroup2      ( NAME = DB1_Group2,          FILENAME = 'd:\DB1_Group2.ndf',          SIZE = 10,          MAXSIZE = 50,          FILEGROWTH = 5 ),      ( NAME = DB2_Group2,          FILENAME = 'd:\DB2_Group2.ndf',          SIZE = 10,          MAXSIZE = 50,          FILEGROWTH = 5 )      LOG ON      ( NAME = TestDB_log,          FILENAME = 'd:\TestDB_log.ldf',          SIZE = 50MB,          MAXSIZE = 500MB,          FILEGROWTH = 10MB ) ;  
de7cc5e663da49cd879b2437154370c1

文章来源:智云一二三科技

文章标题:SQLServer创建数据库详解

文章地址:https://www.zhihuclub.com/43165.shtml

关于作者: 智云科技

热门文章

评论已关闭

32条评论

  1. largest part of the brain controls voluntary muscle movement vision speech hearing thought memory PubMed Kadioglu A Grohmann W Depko A Levinson IP Sun F Collins S.

  2. In the absence of maintenance rehabilitation therapy this change may confirm a genuine change in lifestyle.

  3. Alternative ways of inducing pancreatitis have been described alcohol induced, diet induced, and immune induced, presenting advantages and disadvantages see review for detailed description of these models 79 So supporting your system with DIM, is a good healthy thing to do for detoxification

  4. skelaxin mylan clindamycin 300 mg In recent years, Canada has largely abandoned the idea of R2P in official discourse, even as a multitude of think tanks and non governmental organizations, some bearing the doctrine s name, have sprouted up to promote it

  5. The use of aryl tert butyl sulfones as electrophilic coupling partners was described by the group of Julia Thus, limiting the intensity and duration of Cre expression attenuated toxicity in mammalian cells 16, 18

  6. 2458 Singapore dollars Additional reporting by Anshuman Daga in SINGAPORE and SonaliPaul in MELBOURNE; Writing by Edwina Gibbs; Editing by Ryan Woo Trent ntAJWKUDZuUHdmaWAQ 5 20 2022

  7. manforce prevacid 15mg Finally, some of the pressure for reform is now coming from Ben Bernanke

  8. Supernatants were incubated with anti EGFR antibody overnight at 4 C and A G agarose beads for 2 h at 4 C

  9. It has also recorded a more than 300 million paper loss on its 1 billion bearish bet against Herbalife 6632443 October 14, 2003 Borowy Borowski et al

  10. Balamurugan K com 20 E2 AD 90 20Da 20Sa 20Kupit 20Viagra 20Bez 20Receptu 20 20Esfarmacos 20Comprar 20Viagra 20Barato 20Online esfarmacos comprar viagra barato online So called FREE TRADE is a mechanism by which a wealthy subset of Americans sell out the American middle class, for large sums of money, and keep the money for themselves

  11. Initial coverage should include gram negative enteric bacteria and gram positive cocci, which are responsible for 90 of infections

  12. This underscores the need for timed, controlled nutrient intake before tissue sampling in future placebo controlled studies to make adequate assessments of omega 3 effects on the mTOR pathway in benign breast tissue 53

  13. The products of the genes affected by nuclear estrogen receptor dimers are proteins and peptides such as enzymes, inflammatory peptides, and neurotransmitters

  14. At the end of the live broadcast, Luo Jia list of male enhancement products solemnly announced a big news

  15. Monitor Closely 2 rifabutin will decrease the level or effect of ribociclib by affecting hepatic intestinal enzyme CYP3A4 metabolism

  16. Application of the muscarinic antagonist atropine had no further effect on post junctional responses Panels Aiv F repaglinide ivermectin covid daily mail Pikmin 3 did have a few less days to register sales for its first week charts; a Media Create chart week runs from Wednesday to the following Tuesday, and Pikmin 3 launched on a Saturday

  17. By the end of the interview, there was the sense that the unruffled Archbishop had treated his audience like adults Of course, there is always the possibility of a draft day splash deal

  18. On the other hand, doxycycline has been shown to increase the intracellular concentration of macrocyclic lactones, which makes the combination treatment ivermectin doxycycline worth of further investigation 25

  19. M was started on clomiphene therapy at a dose of 50 mg daily for treatment of hypogonadism of unknown etiology and infertility

  20. COMMENT Human studies trump animal and test tube experiments every time Serious Use Alternative 1 tacrolimus decreases effects of rabies vaccine chick embryo cell derived by pharmacodynamic antagonism

  21. 85V0500 FATROCORTIN INJECTION 1MG ML, 100ML I d say give it some time to even out, and hopefully after a bit your cyle will be back to normal

  22. Natural hormone fluctuations can cause this, as can lifestyle factors like being overweight or stressed Is Gynecomastia on the Rise

  23. From Bach to Tupac Using an Electronic Course Portfolio to Analyze a Curricular Transformation

  24. Here we show that the transcription factor Oct1 is dispensable for mouse gut epithelial cell homeostasis, but is essential for recovery of the colon following damage in vivo, and for passage of intestinal organoids in vitro Ery Tab erythromycin delayed release tablet is a prescription drug used to treat various bacterial infections, including respiratory infections, skin infections, diphtheria, and pertussis

  25. acute myelogenous leukemia AML a rapidly progressing cancer of the blood in which too many immature not fully formed granulocytes, a type of white blood cell, are found in the bone marrow and blood

  26. The exact mechanism of the movement remains mysterious, as the Hh signal must be continuously bound, released, and bound again

网站地图