To create a database:
Command: Create database name;
Example: Create database student;
To delete a database:
Command: drop database name;
Example: Drop database student;
New table:
Command: CREATE TABLE table name
(Column name data type, column Name 2 ...)
Example: CREATE TABLE Student
(Sname char (), Sid Int)
To delete a table:
Command: DROP table name
Example: Drop table Student
To modify a table structure:
(Insert (new) column)
Command: ALTER TABLE name
Add new column name data type
Example: ALTER TABLE student
Add Sage int
(Delete column)
Command: ALTER TABLE name
Drop Column Name
Example: ALTER TABLE student
Drop Column SID
(Modify column type)
Command: ALTER TABLE name
ALTER COLUMN name data type
Example: ALTER TABLE student
Alter column SID float (floating point type)
(New constraint)
Command: ALTER TABLE name
ALTER COLUMN name new data type
Example: ALTER TABLE student
ALTER COLUMN PK_SID PRIMARY KEY (The new constraint type is a PRIMARY KEY constraint)
(delete constraint)
Command: ALTER TABLE name
Drop Column Name
Example: ALTER TABLE student
Drop Pk_sid
Query table content:
Command: Select the data column name to query
From table name
where filter condition (unable to filter data after grouping)
(Advanced search) "Group By column name (group)
Having filter criteria (only filtered data after grouping)
ORDER BY ordering (the final output of the control data is arranged in a positive order: ASC, Flashback: DESC) "
Example: Select SID
From student
where sid=2
The GROUP by Sid
Having sid=1
ORDER BY DESC "
Inserting data into a table: (the value must correspond to the column one by one)
command: INSERT INTO table name
(column name, column name)
Values
(Value, value)
Example: INSERT INTO table name
(Sname,sid,sage)
Values
(' Zhang San ', 12,15)
To modify data values in a table:
command: Update from table name
Set Column name = new value
Example: Update from student
Set Sname= ' John Doe '
Query mode: (BULK insert multiple data)
command: INSERT into table name (the total number of values must be the same as the total number of columns)
Select value, value, value UNION ALL
Selevt value, value, value
Example: INSERT INTO table name
Select ' Zhang San ', 15,18
Select ' John Doe ', 16,19
View:
Command: CREATE VIEW name
As
Select column
From table name
Example: CREATE VIEW students
As
Select Sname
From student
SQL Server Database Common commands