Basic syntax of SQL server
Data type
Exact number
Approximate number
String
Unicode string
**
1. Create a tabl
Create table table name (column name 1 data type (size), column name 2 data type (size) column name 3 data type (size))
Delete tabl
Drop table
Add column
ALTER TABLE table name
ALTER COLUMN column name data type (size)
Column: alter table www add remarks nvarchar (10)
# add a comment column to the www table
* * modify the data type of the column * * ALTER TABLE table name
ALTER COLUMN column name data type (size)
Column: alter table www alter column remarks nvarchar (1000)
# modify the 'remarks' column data type length to 1000 in the www table
Delete column
ALTER TABLE table name
DROP COLUMN column name
Column: alter table www drop column comment
# delete the "remarks" table name from the www table
Insert data
INSERT [INTO] [column name] VALUES
Column: insert into www values ('10-10-11 'tomatoes,' vegetables', '2.1-10-11')
# add a column of data to the www table
Update data
UPDATE SET [WHERE]
Set can be followed by the values of multiple data columns, and no one where can be used to restrict conditions.
Column: update www set sales Price = 1000 where name = 'Apple'
The sales price of # www update is 1000, effective only for those whose name is Apple.
Delete data
1.delete delete statement
DELETE FROM [WHERE]
Column: delete from www where name = 'Apple'
# Delete the data named Apple in the www table
2.Truncate Table statement
The Truncate Table statement can only be used to delete the contents of the entire table
Column: Truncate table www
# Delete everything in the www table
Data query
Conditional expression
Comparison operator
Wildcard character
Logical operator
Select from www | query www table
Select name, title, base salary from www | query in www table only shows name, position and base salary.
Select name from www where Job = 'Finance Department' | query job in www table = employee of Finance Department
Select from www where salary betweer 8000 and 10000 | query the information of employees with www salary ranging from 8000 to 10000.
Select from www where salary 20000 | query the information of employees with less than 10000 or more than 20000 in www table
Select from www where salary in (8000,9000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000) |
Select from www where name like 'Zhang%' | query employee information whose names begin with Zhang in the www table
Select from www where name like 'Yang%' and Job = 'Finance Department' | query www surname Yang and is an employee of Finance Department
Select from www where hobby is not null | query the information of employees whose hobbies are empty in the www table.
Select top 5 from www | query the first five lines of data in www
Select name as name, sales location as xxx, sales price as ddd from sales | set alias
Select * from www order by basic salary desc | query the employee information of www table and display it from high to low
Select distinct Job from www | query which jobs are in the www table and remove duplicates
Select name, title, gender into new1 from www | query the name, title and gender in the www table, and check it in the new table.