Home > News list > Programming/Database >> Database Operation Tutorial

Summary of three methods for creating SQL Server databases

Database Operation Tutorial 2023-05-12 12:13:22 Source: Network

catalogue1 Creating a database using SQL Server Management Studio2 Create a database using the CREATE DATABASE statement.3 Creating a database using a templatesummaryThere are three ways to create a database

There are three ways to create a database.

1 Creating a database using SQL Server Management Studio

2 Create a database using the CREATE DATABASE statement.

3 Creating a database using a template

1 Creating a database using SQL Server Management Studio

Create a file named&quo; Student Course Selection” Student course selection management database for

On the left side of SQL Server Management Studio, there is a&quo; Object Explorer&# quo;, Right click" Database;, Select" Create a new database", Get the following window

Enter&quo; in the database name; Student Course Selection&# quo;, Click 'OK' to create it, and it will be available in" Object Explorer; You can find the student course selection database in the database below

2 Create a database using the CREATE DATABASE statement.

CREATE  The syntax format of the DATABASE statement is as follows

CREATEDATABASEdatabase_ name[ON[PRIMARY][<filespec>[,...n][,<filegroup>[,...n]]][LOGON{<filespec>[,...n]}]][COLLATEcollation_name][WITH<external_access_option>]< filespec>::= (NAME=logical_file_name,FILENAME='os_file_name'[,SIZE=size][,MAXSIZE={max_size|UNLIMITED}][,FILEGROWTH=growth_increment[KB|MB|GB|TB|%]])[,...n]< filegroup>::= FILEGROUPfilegroup_ name[DEFAULT][DEFAULT]< filespec> [,...n]

The parameters are introduced as follows:

  • ON: There is no deep meaning, just a grammar that must be added
  • PRIMARY: keyword, specifies the file of the main file group
  • LOGON: Definition of transaction log files
  • NAME: Specifies the logical name of the file, which is the name used in SQL Server
  • FILENAME: Specify the file name and storage path for the file
  • SIZE: Specify the initial capacity size of the file, which can be measured in kilobytes, megabytes, gigabytes, and terabytes
  • MAXSIZE: Specify the maximum size that a file can grow to, which can be measured in kilobytes, megabytes, gigabytes, and terabytes, or in unlimited (meaning that a file can continuously grow to fill the disk)
  • FILEGROWTH: Specify the size of each increase in file capacity, when the specified data is" 0” When, indicates that the file does not grow. The measurement unit can not only use KB, MB, GB, TB, but also percentage

The specific operations are as follows

one In SQL Server Management Studio, click on&quo; in the toolbar; New Query” Button, or select&quo; File&rdquo& mdash;& mdash;& ldquo; New&rdquo& mdash;& mdash;& ldquo; Database Engine Query; command

2. Enter the following statement in the query editor:

CREATEDATABASE Student Course Selection ON (NAME=Stu_data,/* The logical name of the data file is Stu_data (each statement must be separated by a comma) */FILENAME='C: DATAStu_ Data. mdf ',/* Set file path */SIZE=10MB,/* Initial file capacity is 10MB */MAXSIZE=UNLIMITED,/* File can grow to full disk */FILEGROWTH=10%)/* File can increase capacity by 10% each time */LOGON (NAME=Stu_log,/* The logical name of the log file is Stu_data (each statement should be separated by a comma) */FILENAME='C: DATAStu_ Log. ldf ',/* set file path */SIZE=3MB,/* initial file capacity is 3MB */MAXSIZE=5MB,/* file can grow to 5MB */FILEGROWTH=1MB)/* file can increase by 1MB at a time*/

3. Click on&quo; in the toolbar; Analysis; Button, perform grammar analysis to ensure the correctness of the statement

  4. Click on&quo; Execute” Button, or press F5 to execute the above statement

3 Creating a database using a template

one

  two

  3. Drag and drop the CreateDatabase template into the query editor

4. Replace template parameters

Change the value to a logical name

5. Click on&quo; Analysis; Button for syntax analysis

6. Click on&quo; Execute”

summary

This is an article about SQL; That's all for the article on the three methods of creating a Server database, and more related SQL; Please search for previous articles of Script Home or continue browsing the related articles below to create content for the Server database. We hope everyone can support Script Home more in the future!

Tag: Summary of three methods for creating SQL Server databases


Disclaimer: The content of this article is sourced from the internet. The copyright of the text, images, and other materials belongs to the original author. The platform reprints the materials for the purpose of conveying more information. The content of the article is for reference and learning only, and should not be used for commercial purposes. If it infringes on your legitimate rights and interests, please contact us promptly and we will handle it as soon as possible! We respect copyright and are committed to protecting it. Thank you for sharing.

AdminSo

http://www.adminso.com

Copyright @ 2007~2024 All Rights Reserved.

Powered By AdminSo

Open your phone and scan the QR code on it to open the mobile version


Scan WeChat QR code

Follow us for more hot news

AdminSo Technical Support