Crear Base de Datos SQL
Crear Base de Datos SQL
Applies to: SQL Server (all supported versions) Azure SQL Database
Azure SQL Managed Instance Analytics Platform System (PDW)
This lesson shows you how to create a database, create a table in the database, and
then access and change the data in the table. Because this lesson is an introduction
to using Transact-SQL, it does not use or describe the many options that are
available for these statements.
By using SQL Server Management Studio. This tutorial assumes that you are
using Management Studio, but you can also use Management Studio Express,
which is available as a free download from the Microsoft Download Center.
By using the sqlcmd utility.
By connecting from an application that you create.
The code executes on the Database Engine in the same way and with the same
permissions, regardless of how you submit the code statements.
Prerequisites
To complete this tutorial, you need SQL Server Management Studio and access to a
SQL Server instance.
If you don't have a SQL Server instance, create one. To create one, select your
platform from the following links. If you choose SQL Authentication, use your SQL
Server login credentials.
Create a database
Like many Transact-SQL statements, the CREATE DATABASE statement has a required
parameter: the name of the database. CREATE DATABASE also has many optional
parameters, such as the disk location where you want to put the database files.
When you execute CREATE DATABASE without the optional parameters, SQL Server
uses default values for many of these parameters.
1. In a Query Editor window, type but do not execute the following code:
SQLCopy
CREATE DATABASE TestData
GO
2. Use the pointer to select the words CREATE DATABASE, and then press F1.
The CREATE DATABASE topic in SQL Server Books Online should open. You can
use this technique to find the complete syntax for CREATE DATABASE and for the
other statements that are used in this tutorial.
3. In Query Editor, press F5 to execute the statement and create a database
named TestData.
When you create a database, SQL Server makes a copy of the model database, and
renames the copy to the database name. This operation should only take several
seconds, unless you specify a large initial size of the database as an optional
parameter.
Note
The keyword GO separates statements when more than one statement is submitted
in a single batch. GO is optional when the batch contains only one statement.
Create a Table
APPLIES TO: SQL Server Azure SQL Database Azure Synapse
Analytics Parallel Data Warehouse
To create a table, you must provide a name for the table, and the names and data
types of each column in the table. It is also a good practice to indicate whether null
values are allowed in each column. To create a table, you must have the CREATE
TABLE permission, and the ALTER SCHEMA permission on the schema that will contain
the table. The db_ddladmin fixed database role has these permissions.
Most tables have a primary key, made up of one or more columns of the table. A
primary key is always unique. The Database Engine will enforce the restriction that
any primary key value cannot be repeated in the table.
For a list of data types and links for a description of each, see Data Types (Transact-
SQL)