Overview
As with other high-level languages, there are statements in T-SQL that control the process. The process Control statements in T-SQL further extend the power of T-SQL ... So that most of the business logic can be done at the database level.
One, cross-connection queryThis kind of query is basically not used, because this query method is obtained by the product of two tables (Cartesian set)The syntax is select * from a A, B; Second, internal connection query, can effectively remove the
Please use MySQL for testing.1. Exchange of wages between men and women (E)Idea: use case when to make conditional judgments, modify with Update 1 update salary 2 set sex = 3 case sex 4 when m " Then " f " 5 else m " 6
1. To optimize the query, avoid full-table scanning as far as possible, and first consider establishing an index on the columns involved in the Where and order by.2. Avoid null-valued fields in the WHERE clause, which will cause the engine to
CREATE DATABASE KK;Use KK;CREATE TABLE Fenshubiao(ID INT PRIMARY KEY auto_increment,Mingzi VARCHAR (10),Fenshu FLOAT);DESC FenshubiaoINSERT into Fenshubiao VALUES (NULL, ' AA ', 95.0);The first approach:Select Max (Fenshu) as Second_fenshu from
Gets the modification time of the stored procedure and the creation time of the query--Table select * from sysobjects where id=object_id (N ' table name ') and xtype= ' U ' --table structure select * from syscolumns where id=obje ct_id (N ' table
Suppose you have a table of people (table name: person), if you want to name, ID number, address the three fields exactly the same records to find out, using
1: SELECT p1.*
2: From persons p1,persons p2
3: WHERE
Basic Query methodString condition query,Indexed array Condition queryObject condition QuerySQL statementsThe case is the same,However, there is a lowercase to uppercase conversion when executing, so it's best to write uppercase$condition =new
Find records for all repeating headings:SELECT * from T_info a WHERE ((SELECT COUNT (*) from t_info where Title = A.title) > 1) ORDER by Title DESCOne.find a repeating recordRecorded1. Find all duplicate recordsSELECT * FROM table Where repeating
The database used in this article is db_test and the data table is employeeI. SELECT statement BASIC structureSentence syntax is simply summed up as:SELECT select_list [into new_table_name] [from table_source] [WHERE search_condition] [GROUP by
#示例1: Queries the employee and department tables in an internal connection, and the Age field value in the Employee table must be greater than 25, that is, identify employees older than 25 and the department where the employee is located#SELECT
One: Connection query:Connection query is to connect two or more tables according to a certain condition, select the required data, the connection query query two or more tables at the same time, when there are fields representing the same meaning
Due to some historical reasons, leading to the company's existing projects in the database there are a large number of Chinese table names, the text segment name, and the way to operate the database or SQL statement stitching + ADO, of course, the
Record the problem, although later encountered different, but the use is the sameThere are some ways to use it.COUNT (*) countsGROUP BY groupJoin connection is followed by an on join conditionBetween and what what what betweenIn No in subqueryLike
Introduction to the Decode () function:Main role: Translation of query results into other values (that is, in other forms of expression, the following examples);How to use:Select decode (ColumnName, value 1, translation value 1, value 2, translation
The most important and central part of the SQL language is its query functionality. A query statement is used to retrieve data that already exists in the database according to a specific combination, conditional expression, or order, using a SELECT
Original link: http://www.cnblogs.com/lykbk/p/aefweere45454545454.html1. To optimize the query, avoid full-table scanning as far as possible, and first consider establishing an index on the columns involved in the Where and order by.2. Avoid
LINQ to SQL can query SQL-based data quickly, including the basic object/relation mapper directly in VS, and the O/R mapper can quickly map SQL-based data sources to CLR objects and then use LINQ queries. In the project, right-click Add-New item to
SQL query statement describes the--select statement1. Simple SELECT query statement1.1 Check.Sql> select * from EMP;1.2 Check ListSql> select Empno,ename from emp;1.3 Related queriesSyntax for Oracle:Select a.*,b.* from emp a,dept b where a.deptno=b.
1. View profile settings SHOW VARIABLES like '%profil% 'The results are as follows: profiling off2. Open profile SET Profiling=1Results:3. Execute the SQL you want to executeExplain select* ...4. Query execution of SQL SHOW PROFILESResults:5.
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.