I. Database construction RULES
First paradigm:
Each column in the database is a single data type (Unified data type)
Second paradigm:
Each column in the table is directly related to the primary key
Ii. examples
such as: School Number name Age course score Create a database for a column
You need to divide the two tables first.
First table number name age three column, as Student table, is the primary key table of this database table
The second table fractional number school curriculum score four column, as a score table, is the foreign key table of this database table, the student number in this table is from the students table secondary school number
Student tables and scores in the score table, the relationship between 1:n
Third, the Code
Drop DATABASE Test --delete test databases
CREATE Database Wow--Creating WOW Databases
Use Wow --Using WOW database
Go
CREATE TABLE Warcraft -Creates warcraft tables, creating Name columns, age columns, birthday columns, respectively
(
Name varchar (20),
Age int Primary key identity ( --primary key), the age column starts from 1 and increments by 1 for each additional 1 bars .
Birthday datetime
)
CREATE TABLE Score -Creates the score table, creating the Age column, sage column, course column, score column, respectively.
after the INSERT into Warcraft values is set to self-grow, age in parentheses should not be filled in.
(
Age int PRIMARY KEY,
Sage int references Warcraft (age),
Course varchar (20),
Score Decimal (18,2)--Add unique to the back, indicating that the data in the score column is unique and non-repeatable
)
Go
INSERT into score values (1, ' languages ', 98)--corresponding to the newly created score table
Go
ALTER TABLE warcraft ADD firstname varchar (20)--Modify Warcraft table, add FirstName column
ALTER TABLE Warcraft DROP column FirstName--Modify Warcraft table, delete firstname column
Drop table Warcraft--Delete the entire Warcraft table
Go
Insert into Warcraft values (' Jim ', 15, ' 1999-09-09 ')--Add data to the Warcraft table
Select *from Warcraft--Query all data in Warcraft table
Select Name from Warcraft--Query the Name column data in the Warcraft table
Insert into Warcraft values (' Jerry ', 20, ' 1994-04-04 ')
Select *from Warcraft
Insert into Warcraft (age,name) VALUES (' Tom ')--Add data to the Warcraft table in accordance with (age,name) format
Update Warcraft Set age=23--Modify the Warcraft table to modify all age columns
Update Warcraft set age=24 where name= ' Tom '--Modify the Warcraft table to change the age listed in name to Tom Line
Delete Warcraft where name= ' Jim '--delete the name in the Warcraft table as a Jim row
2014/11/20 SQL Simple Command