E-Book, Englisch, 214 Seiten
A. Masood-Al-Farooq SQL Server 2014 Development Essentials
1. Auflage 2025
ISBN: 978-1-78217-256-7
Verlag: De Gruyter
Format: PDF
Kopierschutz: Adobe DRM (»Systemvoraussetzungen)
Design, implement, and deliver a successful database solution with Microsoft SQL Server 2014.
E-Book, Englisch, 214 Seiten
ISBN: 978-1-78217-256-7
Verlag: De Gruyter
Format: PDF
Kopierschutz: Adobe DRM (»Systemvoraussetzungen)
This book is an easy-to-follow, comprehensive guide that is full of hands-on examples, which you can follow to successfully design, build, and deploy mission-critical database applications with SQL Server 2014. If you are a database developer, architect, or administrator who wants to learn how to design, implement, and deliver a successful database solution with SQL Server 2014, then this book is for you. Existing users of Microsoft SQL Server will also benefit from this book as they will learn what's new in the latest version.
Autoren/Hrsg.
Fachgebiete
Weitere Infos & Material
Creating and modifying databases
You can use either Transact-SQL DDL statements or SQL Server Management Studio to create and modify databases. In the following subsections, we will discuss these options.
Create, modify, and drop databases with T-SQL DDL statements
In this section, we will cover Transact-SQL DDL statements that are used to create, alter and modify SQL Server databases.
Creating a database with T-SQL DDL statements
We use the statement to create a new database on SQL Server. The general syntax for the command is as follows:
The following are the arguments of the command:
- : This is the name of new SQL Server database. The database name must be unique with an instance of SQL Server.
- : This is used to specify the containment status of the database. Specify for non-contained databases, and for partially contained databases.
- : This is used to specify the files in the primary filegroup. If this parameter is not specified, the first file in the list becomes the primary file for the database.
- : This is used to specify the location for the transaction log files.
- : The arguments are used to control file properties. This option is supported for both the data and transaction log file. The parameters include:
- : This is the logical name of the database. We use this name in Transact-SQL statements to refer to the file.
- : This specifies the operating system name and file path.
Note
SQL Server 2014 Database Engine enables you to store SQL Server database files as Windows Azure Blobs Storage. This is one of the new features of SQL Server 2014. For more information about this feature, refer to the article at http://msdn.microsoft.com/en-us/library/dn385720.aspx.
- : This is the initial size of the database file. The value can be specified in KB, MB, GB, or TB.
- : This is used to specify the maximum size limit for the database file. The value can be specified in KB, MB, GB, TB, or as .
- : This is used to specify the automatic growth increments for the database file. The value can be specified in KB, MB, GB, TB, or percentage (%).
- : This specifies the default collation setting for the database. If not specified, the server default collation is used as the database collation. For more information about the Windows and SQL collation names, refer to the topic at http://msdn.microsoft.com/en-gb/library/ms184391(v=sql.120).aspx.
- : This is used to configure the following external excess options:
Note
A detailed discussion about a database's external excess options is beyond the scope of this chapter. For help with this, refer to http://technet.microsoft.com/en-us/library/ms176061(v=sql.120).aspx.
Example 1 – creating a database based on a model database
The following script creates a database using the default parameters from the database:
Tip
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Example 2 – creating a database that explicitly specifies the database data and the transaction log file's filespecs properties
The following script creates the database by explicitly specifying data and the transaction log file's filespecs properties:
Example 3 – creating a database on multiple filegroups
The following script creates the database on the following two filegroups:
- The primary filegroup, which contains and
- The user-defined filegroup, , which only contains the database file, that is,
The following code generates the database:
Modifying a database with T-SQL DDL statements
We use to modify an existing SQL Server database. Some common situations for modifying an existing SQL Server database include:
- Adding or removing filegroups and database files to an existing database
- Adding or removing transaction log files to an existing database
- Manually expanding data and/or transaction log file sizes
- Changing data and/or transaction log file growth settings
- Setting database options
- Changing the database default collation
The following is the basic syntax for the statement:
The following are the arguments of the command:
- : This is the name of a new SQL Server database. The database name must be unique with an instance of SQL Server.
- : This argument adds a file to the database.
- : This will be the name of the filegroup to which the specified file will be added.
- : This argument removes a file from the database.
- : This argument specifies the file that should be modified.
Example – adding a secondary data file to an existing database
The following example uses to add a secondary data file to the database user-defined filegroup ():
You can also use the clause of the statement to change database options. For example, you can run the following command to set the recovery model of the database to :
Dropping a database with T-SQL DDL statements
When you no longer need a database, you can use the statement to delete the database from SQL Server. The following is the basic syntax for :
For example, you run the following command to drop the...




