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