Examples of non-cyclic recursive queries in the SQL Server tree table, tree Recursion
Many people may want to query the content associated with the entire tree-like table through recursive loops... in fact, Microsoft can use other syntaxes in SQL2005 or later versions. The following is an example.
-- Query the parent node with tree as (SELECT * FROM Areas WHERE id = 6 -- the child id to be queried union all
The examples in this article describe SQL Server triggers and transaction usages. Share to everyone for your reference, specific as follows:
Add and remove triggers
Alter TRIGGER TRI_TC on T_c to
Insert,delete
as
begin
set XACT_ABORT on
declare @INSERTCOUNT int;
Update triggers and transactions
Transactions are primarily used for data protection, and when multiple tables are updated, th
+a_salary. 4. write the UPDATE statement "update originsalary set o_salary=" add Value "where o_id=" Get Value "5. Cycle 3 times to complete this function. Another way is to write a stored procedure, which I will not list here. I want you to think about this before learning about cursors, and some examples of batch processing. Some people might say, "Can't the database handle data in one row?" Addsalary the data of the table into rows, and then the t
, thus obtains the desired data successfully, is the master and "rookie" the fundamental difference.According to national conditions, the domestic website with asp+access or SQL Server accounted for more than 70%, php+mysq accounted for 20%, the other less than 10%. In this article, we from the sub-entry, advanced to high-level to explain the ASP injection methods and techniques, PHP injection of the article by the NB Alliance, another friend Zwell wr
Examples of SQL subqueries
1. Single Row subquerySelect ename, deptno, SalFrom EMPWhere deptno = (select deptno from Dept where loc = 'New York ');
2. multi-row subquerySelect ename, job, SalFrom EMPWhere deptno in (select deptno from Dept where dname like 'a % ');
3. Multi-column subquerySelect deptno, ename, job, SalFrom EMPWhere (deptno, Sal) in (select deptno, max (SAL) from EMP group by deptno );
The examples in the books I read when I used to learn connection queries have no practical significance. I just put two tables together and only understood the syntax, but I don't know why I used connection queries, what are the benefits of connection query. Recently, when I was studying Hibernate and reviewing SQL, I thought of a particularly good case (experience: it is difficult to learn
list of students, the place of origin, the form of the student's hometown province, but also some other students of the province of origin. If you only ask which province you can write:23. find out the names of all the students who have enrolled in all coursesSome students above the SQL statement may not understand, the following is a link, point Open has a detailed explanation, to understand helpful https://zhidao.baidu.com/question/258791372.htmlqb
Label:reading: SQL Storage is an important part of the database operation process, for some beginners is also more abstract difficult to understand, this article I will use a few examples to parse the database of SQL stored procedures, so that the abstract things visualized, more easily understood. Example 1: Create proc Proc_stu@sname varchar (20),@pwd varchar (
Tags: style blog color sp on data div log BS--------------------------Examples of Oracle database paging SQL------------------------------------------------SELECT * from ( SELECT TEMP.*, ROWNUM asNUM from ( SELECTEB. Ehr_id,eb. Person_name,cl. svc_id A,bill. svc_id B,bill. Item_name fromPhis. Ehr_base EB, Phis. Svc_clinic Cl,phis. Svc_clinic_bill BILL .WHEREEb. ehr_id=CL. ehr_id andC
reading: SQL storage is an important part of the database operation process, for some beginners is also more abstract difficult to understand, this article I will use a few examples to parse the database of SQL stored procedures, so that the abstract things visualized, more easily understood. Example 1:create proc proc_stu @sname varchar ( -), @pwd varchar ( -)
Usage of distinct in SQL (four examples) and sqldistinct
When using mysql, you sometimes need to query records with unique fields. Although mysql provides the keyword distinct to filter out redundant duplicate records, only one record is retained, but it is often used only to return the number of records that do not repeat, rather than to return all values that do not record the record. The reason is that d
SQL Server uses table values as input parameter examples in stored procedures.
If we want to pass the table as an input parameter to the SQL Server Stored Procedure before 2008, we may need a lot of logic processing to pass the table data as a string or XML.
Table value parameters are provided in 2008. Using Table value parameters, you can send multiple rows of
]AsPARTITION [Partitionfunc]to ([Y2015], [Y2016], [Q1], [Q2], [Q3], [Q4], [PRIMARY])CREATEPARTITIONFUNCTION [Partitionfunc] (datetime)Asrange RIGHT for values (n ' 2016-01-01t00:00:00.000 ', n ' 2017-01-01t00:00:00.000 ', n ' 2017-04-01t00:00:00.000 ', n ' 2017-07-01t00:00:00.000 ', n ' 2017-10-01t00:00:00.000 ', n ' 2018-01-01t00:00:00.000 ') The partition records are as follows: If the partition changes relatively large does not recommend the method of merging and deletion, because error pr
SQL update syntax and Examples
The routine database tutorial is an ever-changing data storage. SQL is used to modify The data that has been updated in The database and delete commands. The update statement can update one or more record commands in The table.
UPDATE table_name
SET column_name = expression
WHERE conditions
Instance 1
UPDATE AntiqueOwners
SET
Call the Java program in Oracle, note: The Java method must be of type static if you want to use System.out/err output log in Java.Need to execute "call Dbms_java.set_output (5000);" In Oracle.First, Helloword1 Write Java program, also write in Sql/plus, and execute.Create or replace and compile Java source named Hello aspublic class Hello {static public string Message (string name) {Return "Hello," + name;}}/2 Publishing Java ProgramsCreate or Replac
District, Peking City, China
This code can be encapsulated as a stored procedure based on the above
-----stored procedure, recursively gets the tree region table string
if exists (select * from sysobjects where name= ' sp_getareastr ')
drop proc sp_getareastrgo
--exec sp_helptext ' sp_getareastr '
--go
exec sp_getareastr go
Query result: Lingbi County, Suzhou, Anhui Province, China
Table structure used:
Partial data:
The above is a small set to introduce the
Tags: asd ble table name IKE blog condition function Post AC1.select: function: Find, Syntax: Select column name from table name (note: You can query multiple columns from one table at a time or query data from multiple table names) Instance: select name from Table1, return all Name in Table1 2.distinct: function: deduplication, Syntax: SELECT DISTINCT column name from table name (note: You can remove duplicate fields under the same column name) Example: SELECT distinct name from Table1, returns
;--three tables joint query two tables in the connection and then and another outside the junction such as query all employee's name, department name, second occupation, some no second occupation, so with external connection select E.ename,d.dname,b.job from emp e,dept D , bonus B where e.deptno=d.deptno and e.ename = B.ename (+);-If there are no employees in some departments, and some employees do not have a department this situation to query all the information needs to use the full connection
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.