SQL CREATE TABLE

Source: Internet
Author: User

Creation of tables

1. Create column (field): Column name + type

2. Set the primary key column: the ability to uniquely represent a single piece of data

3. Set Unique key: Design--index/Key--add--Unique key (select column)--OK

The contents of a unique key cannot be duplicated

4. Foreign key Relationship: a table (from a table) where one of the columns refers to the primary key table in another table (primary table)

The purpose of foreign key relationships is to make the database more complete and more secure.

FK foreign key PK primary key

Because there are various relationships, SQL Server databases are generally referred to as relational databases

Design Table:

The three main paradigms of the database:

1. First paradigm: (Atomicity of each column)

Each column is the smallest atom in a program that does not open the split

2, the second paradigm: (each column must be related to the primary key)

Federated primary Key

3, the third paradigm: (each column must have a self-built relationship with the primary key)

T-SQL statement:

Creating database: Create Database name

Working with databases (switching databases): Use database name

To create a table:

CREATE TABLE Table name
(
code int,
Name varchar (50)
)

Use MyTest
Go
CREATE TABLE Minzu
(
Code varchar (primary key),
Name varchar (50)
)
Go
CREATE TABLE Renyuan
(
Code varchar (primary key),
Name varchar (unique),
Sex bit,
Nation varchar () NOT NULL references Minzu (code),
Birthday datetime
)


CREATE TABLE Friends
(
IDS int identity primary Key,
Mecode varchar (50),
FCode varchar (50)

)

Self-growing column

Key words

If more than one statement is to be executed together, the GO keyword is required after each statement
To create a foreign key relationship table, create a primary table, and then create a table

Primary key primary Key can only occur once
Unique single key can appear multiple times
Not NULL non-null
References foreign key relationship (reference)
Identity self-growth

SQL CREATE TABLE

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.