Explain basic SQL syntax and SQL syntax
1. Create a database
Create database Name
2. delete a database
Drop database name
3. Back up SQL server
The device that creates the backup data
Use master
Exec sp_addumpdevice 'name', 'new name', 'path'
Start backup
Backup database pubs to new name
4. Create a table
Create table Name (column name 1, column name 2)
5. Create a new table based on an existing table
Create table new table name like old table name
Create table new table name as select column name from old table name defintion only
6. Add a column
Alter table name add column Name Data Type
7. Add a primary key
Alter table name add primary key (column name)
8. The auto-increment id attribute is added with 1 each time starting from 1.
Identity (1, 1)
9. Create an index
Create index name on table name (column name)
10. delete an index
Drop index idx_name
11. CTE Query
;with t as(select openid,ROW_NUMBER()over(partition by openid order byopenid)as rowfrom #temp)delete t where row>1
12. case when usage (modify the table name id. If the name of t is not blank, it is still the name of t. Otherwise, it is changed to the name of the table, output modified data to a temporary table)
Update pnset pn. id = case when t. id> ''then t. id else pn. id endoutput deleted. id into temporary table from table name pn with (nolock) join # temp t
13. query, insert, delete, sum, average, and maximum
Select * from tableinsert into new_table (id, name) values (1, 'zhang san') delete from table where range select sum (field1) as sumvalue from table1select avg (field1) as avgvalue from table1select max (field1) as maxvalue from table1
I hope this article will help you explain the basic SQL syntax through the above content.
Articles you may be interested in:
- In-depth analysis of mysql "on duplicate key update" Syntax
- Use of replace syntax for MYSQL batch replacement
- Complete syntax and parameter description of various triggers in SQL SERVER
- SQL Server database syntax
- Jdbc SQL syntax
- SQL Server Stored Procedure syntax
- Analysis of Mysql Join syntax and Performance Optimization
- SQL syntax summary for querying by page in Oracle