- Sentence function
- Data operation
SELECT - Retrieves data lines and columns from the database table
INSERT - Add new data to the database table
Delete - Remove Data Row from Database Table
Update - Update the data in the database table
- Data definition
CREATE TABLE - Create a database table
DROP TABLE - Remove the table from the database
Alter Table - Modify Database Table Structure
CREATE VIEW - Create a view
DROP View - Remove View from the Database
CREATE INDEX - Create an index for database tables
Drop Index - Remove Index from the Database
CREATE Procedure - Create a stored procedure
Drop Procedure - Remove stored procedures from the database
CREATE TRIGGER - Create a trigger
DROP TRIGGER - Remove the trigger from the database
Create Schema - Add a new mode to the database
DROP Schema - Remove a mode from the database
Create Domain - Create a data value domain
Alter Domain - Change the domain definition
DROP DOMAIN - Remove a domain from the database
- Data Control
Grant - Grant user access
Deny - Reject user access
Revoke - Release User Access Permissions
- transaction control
Commit - End current transaction
Rollback - abort current transaction
SET Transaction - Defines the current transaction data access feature
- Documentation SQL
Declare - Set the cursor for the query
Explan - Describe the data access plan for the query
Open - Retrieval Query Open a cursor
FETCH - Retrieve a line of query results
Close - Close Cursor
Prepare - Prepare SQL statements for dynamic
Execute - Dynamically perform SQL statements
Describe - Description ready for query
--- Local variable declare @id char (10) - set @ID = '10010001'select @ID =' 10010001 '
--- Global variable - must start with @@
- IF Elsedeclare @x int @y int @z @ @X = 1 @Y = 2 @ z = 3if @x> @YPRINT 'X> Y' - Print string 'x> Y'Else if @Y> @zprint 'y> Z'Else Print' Z> Y '
--Caseuset e_wage = Casewhen Job_LAGE = '1' TEN E_WAGE * 1.08When Job_WAGE * 1.08When Job_LEVEL = '2' TEN E_WAGE * 1.07When Job_LEVEL = '3' TEN E_WAGE * 1.06ELSE E_WAGE * 1.05nd
--While Continue BreakDeclare @x int @x = 1 @ y = 1WHILE @X <3beginprint @X - the value of print variable x While @Y <3begInselectr @c = 100 * @ x @Yprint @C - Value of print variable C SELECT @Y = @y 1ndselect @X = @X 1select @Y = 1END
--Waitfor - Example Waiting for 1 hour 2 points after 3 seconds to perform SELECT statement waitfor delay '01: 02: 03'select * from Employee - Case, etc. Behind 11:00, then execute SELECT statement waitfor Time ' 23: 08: 00'Select * from Employee *** SELECT ***
select * (column names) from table_name (table) where column_name operator valueex :( host) select * from stock_information where stockid = str (nid) stockname = 'str_name' stockname like '% find this%' stockname like '[a- ZA-Z]% '-------- ([] Specified value range) Stockname Like' [^ fm]% '--------- (^ exclude specified range) --- ------ You can only use wildcards in WHERE clauses using the LIKE key) or stockpath = 'stock_path'or stockNumber <1000and stockIndex = 24Not Stocksex =' Man'StockNumber Between 20 and 100stockNumber in (10, 20, 30) Order by stockid desc (ASC) --------- Sort, DESC - Descending, ASC-Ascending Order by 1, 2 --------- BY list stockName = (Select stockname from "STOCKNAME FROM Stock_information where stockid = 4) --------- Subqueries --------- Unless you can make sure that the inner SELECT returns only a row, ------- otherwise In the outer WHERE clause, use a IN Law Select Distinct Column_Name Form Table_Name --------- DistINCT specified to search the alone, do not repeat the Select stockNumber, "stocknumber 10" = stockNumber 10 from table_nameselector Stockname, "stocknumber" = count (*) from table_name group by stockname --------- Group by Packet table, specify the same value in the specified column HAVING Count (*) = 2 ---- ----- Having Selected Group Select * from Tab Le1, Table2 WHERE TABLE1.ID * = Table2.ID -------- Left external connection, there is no NULL in Table1 to represent table1.id = * Table2.ID ------- - Right external connection
Select stockname from table1Union [all] ----- UNION merge query result set, all-reserved repeat line Select stockname from table2
*** insert ***
INSERT INTO TABLE_NAME (STOCK_NAME, STOCK_NUMBER) Value ("XXX", "XXXXX") Value (SELECT stockname, stock_table2) --- value is a SELECT statement
*** UPDATE ***
Update table_name set stockName = "xxx" [Where stockid = 3] stockname = defaultStockName = nullstocknumber = stockname 4 *** delete ***
Delete from table_name where stockid = 3truncate table_name ----------- Delete all rows in the table, still keep the integrity of the table DROP TABLE_NAME ------------- complete Delete table
*** alter Table *** --- Modify the database table structure
Alter Table Database.OWNER.TABLE_NAME ADD Column_name Char (2) NULL ..... sp_help table_name ---- Display Table Existing Create Table Table_name (Name Char (20), Age Smallint, Lname Varchar (30)) INSERT INTO TABLE_NAME SELECT ......... - - Realize the method of deleting columns (Create a new table) ALTER TABLE TABLE_NAME DROP CONSTRAINT stockName_Default ---- Delete the stockname's default constraint *** function (/ * commonly used function*/)***
---- Statistical Function ---- AVG - Ask the average COUNT - Statistics Max - Search MIN - Summary SUM - Search
--AVGUSE PANGUSELECT AVG (E_WAGE) AS DEPT_AVGWAGEFROM EMPLOYEGROUP BY DEPT_ID
--MAX - Survey the highest payroll Name USE PANGUSELECT E_NAMEFROM EMPLOYEEWHERE E_WAGE = (SELECT MAX (E_WAGE) from EMPLOYEE)
--Stdev () - stdev () function Returns the standard deviation of all data in the expression
--Stdevp () - stdevp () function returns the overall standard difference
--VAR () - VAR () function returns a statistical variation of all values in the expression
--VARP () - VARP () function Returns the total variation
---- Arithmetic function ----
/ *** Triangle function *** / sin (float_expression) - Returns sinusoidal COS (FLOAT_EXPRESSION) in an arc - Returns the cosine TAN (FLOAT_EXPIXPRESSION) in the arc-represented angle - Returns the angle represented by radians Orthodium COT (FLOAT_EXPRESSION) - Returns the remainder of the angle represented / *** Anti-triangular function *** / asin (float_expression) - Returns the sinusoidal is the angle ACOS (float_expression) indicated by the FLOAT value. - Returning the cosine is the angle ATAN (float_expression) of the float value - Return to the angle ATAN2 (float_expression1, float_expression2) of the float value - Return to orthode chitting is FLOAT_EXPRESSION1 / FLOAT_EXPRES-SION2 in the arc. Corner DegRees - Transform the arc into angle returns the same data type as the expression can be the same as the integer / money / real / float type radians (numeric_expression) - convert the angle to the arc return to the same data as the expression Types can be -integer / money / real / float type exp (float_expression) - Return Expression LOG (FLOAT_EXPRESSION) - Returns the natural log of log10 (float_expression) - Returns 10 For the end of the logarian SQRT (FLOAT_EXPRESSION) - Returns the square root of the expression / *** Nearly close to the similar value *** / ceiling (numeric_expression) - Return> = The minimum integer returned by the expression is the same as the expression To - ITEGER / MONEY / REAL / FLOAT Type Floor (Numeric_Expression) - Returns the data type returned by <= the minimum integer returned by the expression is the same as the expression of the same --integer / money / real / float type Round - Returns the data returned by integer_expression as accuracy - Types and expressions can be integer / money / real / float type ABS (Nume) RIC_EXPRESSION) - The data type returned by the error of the expression can be the same as the expression of the expression of -integer / money / real / float type Sign (Numeric_Expression) - the positive number of the test parameters returns 0 zero value 1 positive or -1 negative data type - the same can be used for Integer / Money / REAL / FLOAT type PI () - return value is π 3.1415926535897936rand ([Integer_Expression]) - Do it with optional [integer_expression] Seeds worth 0-1 random floating point numbers
---- String Function ---- ASCII () - Function Returns the ASCII code value of the character express left-end character Char () - Function is used to convert the ASCII code to the character - if not entered 0 ~ 255 The ASCII code value char function returns a NULL value LOWER () - function transforms all the strings to lowercase UPPER () - Function Converts the string to the uppercase STR () -Function to convert numeric data conversion For the character data Ltrim () - function removes the space of the string head removes the RTRIM () - function removes the space of the string of the string to Left (), substring (), substring () - Function Return to some strings Charindex (), Patindex () - Function Returns the start position of a specified substring in the string Soundex () - function Returns a four-bit character code - Soundex function can be used to find sound similar strings, but Soundex functions Return to numbers and Chinese characters to return 0 Values DIFFERENCE () - Functions Returns the difference between the two character expressions returned by the SoundEx function - 0 two SoundEx functions return value different - 1 two SoundEx function returns the first character of the value of the same - 2 Two SoundEx functions return values The first two characters of the value of the same - 3 Two SoundEx functions return values The first two three characters of the value - 4 two SoundEx functions The return value is completely the same quotename () - function returns a string from a specific pen / * select quotename ('abc', '{') quotename ('ABC') running results --------- ------------------------- {{abc} [ABC] * /
Replicate () - Function Returns a string of repeating character_expression specified / * SELECT Replicate ('ABC', 3) Replicate ('ABC', -2) Run the results below ----------- ---------- Abcabcabc null * /
Reverse () - Function Run the specified string Character arrangement reverse the Replace () - function returns the string of the specified substring / * SELECT Replace ('ABC123G', '123', 'DEF') The results are as follows ----------- ----------- Abcdefg * /
The space () - function returns a blank string stuff () - function with a specified length, replacing a string of the position length with another subster
---- Data Type Conversion Function ---- Cast () Function Syntax As next () (
SELECT CAST (100 99 As Char) Convert (VARCHAR (12), getdate ()) running results --------------------------- --- ------------ 199 Jan 15 2000
---- Date Function ---- DAY () - Function Returns the Date_Expression Date () - Function Returns the Month Value Values in Date_Expression Year () - Function Returns the Year Value Dateadd in Date_Expression (