1. Create a table
Grammar:
CREATE Table Table Name
(
Column Name 1 data type 1,
Column Name 2 data type 2,
Column Name 3 data type 3,
)
For example:
CREATE TABLE Teachers ( varchar, bit , integer )
2. Create a table in the specified database
Using the USE statement to reference the specified database, you can create a table in the database
Grammar:
Use database name
CREATE Table Table Name
(
Column Name 1 data type 1,
Column Name 2 data type 2,
Column Name 3 data type 3,
)
For example:
Use Customers CREATE TABLE Teachers ( varchar, bit , integer)
Some of the data types commonly used in SQL are summarized in the following table:
Data type |
Describe |
Integer (size) int (size) smallint (size) tinyint (size) |
Holds integers only. Specify the maximum number of digits within the parentheses. |
Decimal (SIZE,D) Numeric (SIZE,D) |
Accommodates numbers with decimals. "Size" Specifies the maximum number of digits. "D" Specifies the maximum number of digits to the right of the decimal point. |
char (size) |
Holds a fixed-length string (which can hold letters, numbers, and special characters). Specifies the length of the string in parentheses. |
varchar (size) |
Accommodates variable-length strings that can hold letters, numbers, and special characters. Specifies the maximum length of the string in parentheses. |
Date (YYYYMMDD) |
accommodate the date. |
SQL Server Database Tutorial Two, creating a database table