-- statement function
--Data manipulation
SELECT--retrieve data rows and columns from the database table
INSERT--add new data rows to the database table
DELETE--delete data rows from the database table
UPDATE--update data in the database table--data definition
CREATE TABLE--create a Database table
DROP TABLE--delete the table from the database
ALTER TABLE--modify the database table structure
CREATE VIEW--create a view
DROP VIEW--delete the view from the database
CREATE INDEX--create an index for the database table
DROP INDEX--from Delete the index from the database
CREATE PROCEDURE--create a stored procedure
DROP PROCEDURE--delete the stored procedure from the database
CREATE TRIGGER--create a trigger
DROP TRIGGER--delete the trigger from the database
CREATE SCHEMA--add a new schema to the database
DROP SCHEMA--delete a schema from the database
CREATE DOMAIN--create a data value domain
ALTER DOMAIN--change the domain definition
DROP DOMAIN--delete a domain from the database--data control
GRANT--grant user access
DENY--Reject user access
REVOKE--Release user access rights--Transaction control
COMMIT--End current transaction
ROLLBACK--Abort current transaction
SET TRANSACTION--Define current transaction data access characteristics
--programmatic SQL
DECLARE--set cursor for query
EXPLAN--describe data access plan for query
OPEN--retrieve query result open a cursor
FETCH--retrieve a row of query result
CLOSE--close cursor
PREPARE--prepare SQL statement for dynamic execution
EXECUTE-- Execute SQL statement dynamically
DESCRIBE--describe prepared query
---local variables
declare @idchar(10)
--set @id='10010001'
select @id='10010001'
---Global variables
---Must start with @@
--IF ELSE
declare @x int @y int @z int
select @x=1 @y=2 @z=3
if @x>@y
print'x>y'--打印字符串'x>y'
else if @y>@z
print'y > z'
elseprint'z > y'
--CASE
use pangu
update employee
sete_wage=
case
when job_level = ‟1‟ then e_wage*1.08
when job_level = ‟2‟ then e_wage*1.07
when job_level = ‟3‟ then e_wage*1.06
else e_wage*1.05
end
--WHILE CONTINUE BREAK
declare @x int @y int @c int
select @x = 1 @y=1
while @x < 3
begin
print @x -- print the value of variable x
while @y < 3
begin
select @c = 100*@x + @y
print @c -- print the value of variable c
select @y = @y + 1 end
select @x = @x + 1
select @y = 1
end
--WAITFOR
--Example wait for 1 hour, 2 minutes and 3 seconds before executing the SELECT statement waitfor delay '01:02:03' select * from employee --Example wait until after
11:08 p.m. before executing the SELECT statement
waitfor time '23:08 :00'
select * from employee
***SELECT***
select *(column name) from table_name(table name) where column_name operator value
ex:(host)
select * from stock_information where stockid = str(nid)
stockname = 'str_name'
stockname like '% find this %'
stockname like '[a -zA-Z]%' --------- ([] specifies the range of values)
stockname like '[^FM]%'--------- (^excludes the specified range)
-- ------- wildcards can only be used in where clauses using the like keyword)
or stockpath = 'stock_path'
or stocknumber < 1000
and stockindex = 24
not stock*** = 'man'
stocknumber between 20 and 100
stocknumber in(10,20,30)
order by stockid desc(asc) --------- sorting, desc-descending, asc-ascending order by 1,2 --------- by column Number
stockname = (select stockname from stock_information where stockid = 4) --------- Subquery --------- Unless it can ensure that the inner select only returns the value of one row, ----- ----Otherwise, an in qualifier should be used in the outer where clause
select distinct column_name form table_name --------- distinct specifies to retrieve unique column values, not repeated
select stocknumber, "stocknumber + 10" = stocknumber + 10 from table_name
select stockname , "stocknumber" = count(*) from table_name group by stockname--------- group by Group the table by row, specifying the same value in the column having count(* ) = 2 --------- having selected the specified group
select *
from table1, table2
where table1.id *= table2.id -------- Left outer join, some in table1 but not null in table2 means
table1.id =* table2.id ------ -- Right external connection
select stockname from table1
union [all] ----- union merge query result set, all-keep duplicate rows
select stockname from table2
***insert***
insert into table_name (Stock_name,Stock_number) value ("xxx","xxxx") value (select Stockname , Stocknumber from Stock_table2)---value 为 select 语句
***update***
update table_name set Stockname = "xxx" [where Stockid = 3]
Stockname = default http://hi.baidu.com/ttcc2009
Stockname = null
Stocknumber = Stockname + 4
***delete***
delete from table_name where Stockid = 3
truncate table_name ----------- Delete all rows in the table, still maintain the integrity of the table drop table table_name --------------- drop table completely
***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 has features
create table table_name (name char(20), age smallint, lname varchar(30)) insert into table_name select ......... ----- Implement the method of deleting columns (create a new table)
alter table table_name drop constraint Stockname_default ---- delete the default constraint of Stockname
Shangxuetang brings a brand-new Java300 course to students! Java zero-basic self-study Java must-have high-quality tutorial
Follow "BlankLB", you can get a lot of programming materials source code courseware without waste