T-SQL statements

Source: Internet
Author: User


Creation of tables:
1. Create column (field): Column name + type
2. Set Primary key column (primary key): Ability to uniquely identify a single piece of data
3. set Unique (unique): content cannot be duplicated
4. foreign key relationship: a table (from a table) in which a column refers to a primary key column from another table (the primary table)


Design Table:

The three main paradigms of the database:

1. First Paradigm : (Atomicity of each column)
Each column is the smallest atom that is non-detachable in a program.

2. Second Paradigm : (each column is related to the primary key column)

3. The third Paradigm : (each column is directly related to the primary key)


FK foreign key PK primary key

T-sql:

1. Creating database: Create databasename

2. Using the database: Use database name

3. Create a data table :

CREATE TABLE Renyuan
(
Code varchar ( primary key),
Name varchar (unique) ,
Sex bit,
Nation varchar () not null references Minzu (code),
Birthday datetime
)

CREATE TABLE Minzu
(
Code varchar ( primary key),
Name varchar (50)
)

CREATE TABLE Friends
(
IDS int identity primary key,
Mcode varchar (50),
FCode varchar (50)
)

Self-growth column : Identity self-growth integer with the master key meaningless delete a column does not change the number (example: Deleted 3 The next line by default is 4)

go: If multiple statements are to be executed together, then the GO keyword will be added after each statement

when creating a foreign-key table, Create a primary table first , re-create from table

Key Words :

primary key primary key
Unique Uniqueness Key
Not null non-null
Foreign key relationship:references table name (referenced column)
identity self-growth

T-SQL statements

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.