HQL statement Daquan (change)

2010-03-29  来源:本站原创  分类:Java  人气:585 

Hibernate is equipped with a very powerful query language that looks very much like SQL. But do not be grammatical structure of the confusing similarity, HQL is very conscious of is designed to be fully object-oriented queries, it can understand concepts such as inheritance, polymorphism and association of the class concept.

Chapter 15 HQL: Hibernate Query Language
Hibernate is equipped with a very powerful query language that looks very much like SQL. But do not be grammatical structure of the confusing similarity, HQL is very conscious of is designed to be fully object-oriented queries, it can understand concepts such as inheritance, polymorphism and association of the class concept.

15.1. Case-sensitive issue, besides the name of the Java classes and attributes, the query is not sensitive to the case. So SeLeCT and sELEct and SELECT is the same, but the org.hibernate.eg.FOO is not equivalent to org.hibernate.eg.Foo and foo.barSet not equivalent to foo.BARSET.

HQL keywords in this manual will use lowercase letters. Many users find using a fully capitalized keyword will query more readable, but we found that when the query statement embedded into the Java key to use uppercase when more ugly word.

15.2. From clause
Hibernate query in the simplest form of the following:

from eg.Cat the clause simply returns all instances of the class eg.Cat. Usually we do not need to use the fully qualified class name, because the auto-import (automatic introduction) is the default situation. So we almost exclusively use the following simple formulation:

from Cat In most cases, you need to specify an alias, because you may need to query the rest of the reference to the Cat

from Cat as cat this statement alias cat to Cat instances assigned to the class, so that we can in the following query using this alias. Keyword as is optional, we could write:

from Cat cat clause can appear multiple classes at the same time, the query result is to produce a Cartesian product or generated by cross-table connection.

from Formula, Parameterfrom Formula as form, Parameter as param query the alias in the beginning of the lowercase is considered a good practice habits to do so with the Java variable naming standards to maintain a consistent (for example, domesticCat).

15.3. Association (Association) and connectivity (Join)
We can also even for the associated entity is a collection of all the elements in the specified an alias, when you want to use keyword join.

from Cat as cat inner join cat.mate as mate left outer join cat.kittens as kittenfrom Cat as cat left join cat.mate.kittens as kittensfrom Formula form full join form.parameter param connection types are supported to learn from from the ANSI SQL come.

inner join (in connection)

left outer join (left outer join)

right outer join (right outer join)

full join (fully connected, not commonly used)

Statement inner join, left outer join and right outer join can be abbreviated.

from Cat as cat join cat.mate as mate left join cat.kittens as kitten Also, a "fetch" connection to allow only the use of a select statement will be associated with an object or a set of values with their parent objects initialization has been initialized, this method using the case to the collection is particularly useful, for associations and collections, it effectively replaces the mapping file in the outer join with the delay in the statement (lazy declarations). View Article 20.1 "fetching strategy (Fetching strategies)" to obtain and many other information.

from Cat as cat inner join fetch cat.mate left join fetch cat.kittens a fetch connections usually do not need to be designated an alias, because the associated objects should not be used in the where clause (or any other clause). At the same time, the associated objects are not directly in the query results to return, but they can through their parent object to access them.

Note fetch construct variables using scroll () or iterate () function, the query can not be used. Finally note that the use of full join fetch and right join fetch are not meaningful.

If you are using property-level delays for (lazy fetching) (This is done by rewriting bytecode to achieve), the fetch all properties can be used to force Hibernate immediate access to those who might otherwise need to defer the loading of the property (in the first query) .

from Document fetch all properties order by namefrom Document doc fetch all properties where lower (doc.name) like '% cats% '15 .4. select clause
select clause, choose the kind of objects and properties to return to the query result set. Consider the following situation:

select mate from Cat as cat inner join cat.mate as mate of the statement will select mates of other Cats. (Other cat's spouse) In fact, you can be more concise with the following query to express the same meaning:

select cat.mate from Cat cat query can return a value of any type of property, including the return type of a component (Component) of the property:

select cat.name from DomesticCat catwhere cat.name like 'fri%' select cust.name.firstName from Customer as cust query may return multiple objects and (or) attribute, stored in the Object [] queue,

select mother, offspr, mate.name from DomesticCat as mother inner join mother.mate as mate left outer join mother.kittens as offspr or stored in a List object,

select new list (mother, offspr, mate.name) from DomesticCat as mother inner join mother.mate as mate left outer join mother.kittens as offspr may also be returned directly to an actual typesafe Java object,

select new Family (mother, mate, offspr) from DomesticCat as mother join mother.mate as mate left join mother.kittens as offspr hypothesis class Family has an appropriate constructor.

You can use the keyword as to the "expression has been selected," assign alias:

select max (bodyWeight) as max, min (bodyWeight) as min, count (*) as nfrom Cat cat with the clause of this select new map is most useful when used with:

select new map (max (bodyWeight) as max, min (bodyWeight) as min, count (*) as n) from Cat cat in the query returns a Map object, the contents of an alias and the selected value of the composition of the name - the value of mapping.

15.5. Aggregate functions
HQL queries may even return to the role of aggregate functions on properties on the calculation results:

select avg (cat.weight), sum (cat.weight), max (cat.weight), count (cat) from Cat cat supported aggregate functions are as follows:

avg (...), sum (...), min (...), max (...)

count (*)

count (...), count (distinct ...), count (all. ..)

You can choose to use math operators clause, connectivity, and a proven SQL function:

select cat.weight + sum (kitten.weight) from Cat cat join cat.kittens kittengroup by cat.id, cat.weightselect firstName | | '' | | initial | | '' | | upper (lastName) from Person keyword distinct can also be used with all that they have the same semantics of SQL.

select distinct cat.name from Cat catselect count (distinct cat.name), count (cat) from Cat cat15.6. polymorphic queries a query as follows:

from Cat as cat not only to return to Cat instances of a class, but will also return an instance of DomesticCat subclass. Hibernate can be specified in the from clause of any Java class or interface. query will return all persistent class inherits the instance of the class or the annihilator Back to the statement of the interface for all instances of persistent classes. The following query returns all the objects are persistent:

from java.lang.Object o interface Named might be a variety of persistent class declaration:

from Named n, Named m where n.name = m.name note that the last two queries will require more than one SQL SELECT. This shows that the order by clause to the entire result set is not correctly sorted. (This also shows that you have Such queries can not use the Query.scroll () method.)

15.7. Where clause
where clause allows you to return an instance of the list narrowed down. If you do not specify an alias, you can use the property name to direct reference to the property:

from Cat where name = 'Fritz' If you assigned an alias, need to use the full property name:

from Cat as cat where cat.name = 'Fritz' Returns name (attribute name is equal to) 'Fritz' the Cat class.

select foo from Foo foo, Bar barwhere foo.startDate = bar.date will return all of the Foo class to meet the following conditions: the example of the existence of the bar as an example of its date property Foo is equal to the startDate property. Compound path expressions make the where clause extremely powerful, consider the following situation:

from Cat cat where cat.mate.name is not null the query will be translated into a table containing the connection (inner join) in SQL queries. If you intend to write query like this

from Foo foo where foo.bar.baz.customer.address.city is not null in SQL, you achieve this goal will require a four-table join query.

= Operator can not only be used to compare the value of the property can also be used to compare examples:

from Cat cat, Cat rival where cat.mate = rival.mateselect cat, mate from Cat cat, Cat matewhere cat.mate = mate special attributes (lowercase) id can be used to indicate an object's unique identifier. (You can also use the object's property name.)

from Cat as cat where cat.id = 123from Cat as cat where cat.mate.id = 69 The second query is valid. At this point do not need to connect to the table!

The same can also use the composite identifier. For example Person class has a composite identifier, which consists of country property with medicareNumber attributes.

from bank.Person personwhere person.id.country = 'AU' and person.id.medicareNumber = 123456from bank.Account accountwhere account.owner.id.country = 'AU' and account.owner.id.medicareNumber = 123456 second query does not need to connect to the table.

Similarly, the special properties of class during polymorphic persistence context is used to access an instance of the differential value (discriminator value). A where clause embedded in Java class name will be converted to the class discriminator value.

from Cat cat where cat.class = DomesticCat You can also declare an attribute of type components or composite user types (as well as by the components of the components, etc.). Never try to use a component type to the end of the path expression (path-expression) (On the contrary, you should use an attribute to the end of the component). For example, if store.owner contains a physical address contains a component

store.owner.address.city / / correct store.owner.address / / Error! an "arbitrary" type has two special properties id and class, to allow us to in accordance with the following expression of a connection (AuditLog.item is a property, which has been mapped to <any>).

from AuditLog log, Payment payment where log.item.class = 'Payment' and log.item.id = payment.id note that in the above query with the sentence, log.item.class and payment.class will involve a completely different the database column.

15.8. Expressions allowed in the where clause include most of the expressions you can use the SQL expression types:

Mathematical operators +, -, *, /

Binary comparison operators =,> =, <=, <>,! =, Like

Logical operators and, or, not

in, not in, between, is null, is not null, is empty, is not empty, member of and not member of

"Simple" case, case ... when ... then ... else ... end, and the "search" case, case when ... then ... else ... end

String connector ...||... or concat (...,...)

current_date (), current_time (), current_timestamp ()

second (...), minute (...), hour (...), day (...), month (...), year (...),

EJB-QL 3.0, any function or operator defined: substring (), trim (), lower (), upper (), length (), locate (), abs (), sqrt (), bit_length ()

coalesce () and nullif ()

cast (... as ...), its second parameter is the name of a Hibernate type, and the extract (... from ...), as long as the ANSI cast () and extract () is the underlying database support

Any database supported SQL scalar function like sign (), trunc (), rtrim (), sin ()

JDBC parameters?

Named parameters: name,: start_date, 1

SQL Direct constant 'foo', 69, '1970-01-01 10:00:01.0 '

Java public static final type of constant eg.Color.TABBY

Keyword in and between may be used as follows:

from DomesticCat cat where cat.name between 'A' and 'B'from DomesticCat cat where cat.name in (' Foo ',' Bar ',' Baz ') and the negative form can also be written as follows:

from DomesticCat cat where cat.name not between 'A' and 'B'from DomesticCat cat where cat.name not in (' Foo ',' Bar ',' Baz ') Similarly, the clause is null and is not null may be used to test the null value (null).

In the Hibernate configuration file contains a statement HQL "Query replace (query substitutions)", the Boolean expression (Booleans) expression in other easy to use:

<property name="hibernate.query.substitutions"> true 1, false 0 </ property> system, the HQL into SQL statements, the setting that will be used to replace the characters 1 and 0 keywords true and false:

from Cat cat where cat.alive = true You can use a special property size, or a special function size () to test a set of size.

from Cat cat where cat.kittens.size> 0from Cat cat where size (cat.kittens)> 0 for the index of the (ordered) set, you can use minindex with maxindex functions to the minimum and maximum reference index of ordinal. Similarly, you can use minelement with maxelement function to refer to a collection of basic data types in the minimum and maximum elements.

from Calendar cal where maxelement (cal.holidays)> current datefrom Order order where maxindex (order.items)> 100from Order order where minelement (order.items)> 10000 in the passing of a set of index set or sets of elements (elements and indices function), or pass the results of a sub-query when you can use the SQL functions any, some, all, exists, in

select mother from Cat as mother, Cat as kitwhere kit in elements (foo.kittens) select p from NameList list, Person pwhere p.name = some elements (list.names) from Cat cat where exists elements (cat.kittens) from Player p where 3> all elements (p.scores) from Show show where 'fizard' in indices (show.acts) Note that in Hibernate3 species, these structural variables - size, elements, indices, minindex, maxindex, minelement, maxelement - only can be used in the where clause.

One ever be indexed (ordered) collection of elements (arrays, lists, maps) can be referenced in other index (only in the where clause):

from Order order where order.items [0]. id = 1234select person from Person person, Calendar calendarwhere calendar.holidays [ 'national day'] = person.birthDay and person.nationality.calendar = calendarselect item from Item item, Order orderwhere order . items [order.deliveredItemIndices [0]] = item and order.id = 11select item from Item item, Order orderwhere order.items [maxindex (order.items)] = item and order.id = 11 in the [] in the expression of style could even be an arithmetic expression.

select item from Item item, Order orderwhere order.items [size (order.items) - 1] = item for one-to-many association (one-to-many association), or the value of elements in the collection, HQL also provides built-in index () function,

select item, index (item) from Order order join order.items itemwhere index (item) <5 if the underlying database supports the SQL scalar functions, they can also be used

from DomesticCat cat where upper (cat.name) like 'FRI%' If you can not all of these convinced Consider the following query. If you are using SQL, statement length will increase the amount of decline in the number of readability:

select custfrom Product prod, Store store inner join store.customers custwhere prod.name = 'widget' and store.location.name in ( 'Melbourne', 'Sydney') and prod = all elements (cust.currentOrder.lineItems) Hint: would, like the following statement

SELECT cust.name, cust.address, cust.phone, cust.id, cust.current_orderFROM customers cust, stores store, locations loc, store_customers sc, product prodWHERE prod.name = 'widget' AND store.loc_id = loc.id AND loc.name IN ( 'Melbourne', 'Sydney') AND sc.store_id = store.id AND sc.cust_id = cust.id AND prod.id = ALL (SELECT item.prod_id FROM line_items item, orders o WHERE item.order_id = o.id AND cust.current_order = o.id) 15.9. order by clause query returns a list (list) can be returned in accordance with a class or component (components) of any property (property) to be sorted:

from DomesticCat catorder by cat.name asc, cat.weight desc, cat.birthdate optional asc or desc keywords identified in ascending or descending order.

15.10. Group by clause, an aggregate value return (aggregate values) of the query can be returned in accordance with a class or component (components) of any property (property) to divide:

select cat.color, sum (cat.weight), count (cat) from Cat catgroup by cat.colorselect foo.id, avg (name), max (name) from Foo foo join foo.names namegroup by foo.idhaving clause Here are also allowed.

select cat.color, sum (cat.weight), count (cat) from Cat catgroup by cat.color having cat.color in (eg.Color.TABBY, eg.Color.BLACK) if the underlying database supports it (for example, can not be In MySQL use), SQL functions and aggregate functions in general may also appear in the having and order by clause.

select catfrom Cat cat join cat.kittens kittengroup by cathaving avg (kitten.weight)> 100order by count (kitten) asc, sum (kitten.weight) desc attention to group by clause and order by clause can contain arithmetic expressions (arithmetic expressions).

15.11. Sub-queries to support sub-queries the database, Hibernate support the use of sub-queries in the query. A sub-query must be surrounded by parentheses (often a SQL aggregate function parentheses). Even interrelated sub-query (reference to the external query subquery alias) is also permitted.

from Cat as fatcat where fatcat.weight> (select avg (cat.weight) from DomesticCat cat) from DomesticCat as cat where cat.name = some (select name.nickName from Name as name) from Cat as cat where not exists (from Cat as mate where mate.mate = cat) from DomesticCat as cat where cat.name not in (select name.nickName from Name as name) in the select list contains more than an expression of sub-queries, you can use a tuple constructor Fu (tuple constructors):

from Cat as cat where not (cat.name, cat.color) in (select cat.name, cat.color from DomesticCat cat) note that in some database (not including Oracle and HSQL), you can in other contexts use tuple constructors, such as the user types the query components and a combination of:

from Person where name = ( 'Gavin', 'A', 'King') this query is equivalent to the more complex:

from Person where name.first = 'Gavin' and name.initial = 'A' and name.last = 'King') There are two good reasons to make you such a thing should not be taken: First, it is not completely applicable to each database platform; Second, the query is now dependent on the order of attributes in mapping file.

15.12. HQL Examples
Hibernate queries can be very powerful and complex. In fact, Hibernate is one of the main selling point of the power of query. Here are some examples, they are with my recent use of a project is very similar to the query. Note that you can use most of the inquiries to be simpler than these more!

The following query for a particular customer to pay all outstanding bills to a minimum in the total value of the given circumstances, the return to order id, number of entries and the total value of the total value of the return value according to the results of sorting. In order to determine the price, the query uses the current directory. As a result of the SQL query conversion, using the ORDER, ORDER_LINE, PRODUCT, CATALOG and PRICE library table.

select order.id, sum (price.amount), count (item) from Order as order join order.lineItems as item join item.product as product, Catalog as catalog join catalog.prices as pricewhere order.paid = false and order. customer =: customer and price.product = product and catalog.effectiveDate <sysdate and catalog.effectiveDate> = all (select cat.effectiveDate from Catalog as cat where cat.effectiveDate <sysdate) group by orderhaving sum (price.amount)>: minAmountorder by sum (price.amount) desc This is really a monster! In fact, in real life, I am not keen on subqueries, so my query looks like this:

select order.id, sum (price.amount), count (item) from Order as order join order.lineItems as item join item.product as product, Catalog as catalog join catalog.prices as pricewhere order.paid = false and order. customer =: customer and price.product = product and catalog =: currentCataloggroup by orderhaving sum (price.amount)>: minAmountorder by sum (price.amount) desc a query in each of the following kind of state the number of payments, excluding all in AWAITING_APPROVAL state to pay, because the state has made the current users of the latest changes in the state. The query is converted to contain two internal connections, as well as an associated sub-select SQL query, the query uses the table PAYMENT, PAYMENT_STATUS and PAYMENT_STATUS_CHANGE.

select count (payment), status.name from Payment as payment join payment.currentStatus as status join payment.statusChanges as statusChangewhere payment.status.name <> PaymentStatus.AWAITING_APPROVAL or (statusChange.timeStamp = (select max (change.timeStamp) from PaymentStatusChange change where change.payment = payment) and statusChange.user <>: currentUser) group by status.name, status.sortOrderorder by status.sortOrder instance if I set statusChanges map a list (list), rather than a set (set ), writing query will be easier.

select count (payment), status.name from Payment as payment join payment.currentStatus as statuswhere payment.status.name <> PaymentStatus.AWAITING_APPROVAL or payment.statusChanges [maxIndex (payment.statusChanges)]. user <>: currentUsergroup by status. name, status.sortOrderorder by status.sortOrder The following query uses the MS SQL Server's isNull () function returns the current user belongs to the organization of the organization and organizational accounts unpaid accounts. It was converted into a table ACCOUNT, PAYMENT, PAYMENT_STATUS, ACCOUNT_TYPE, ORGANIZATION, and ORG_USER conducted three months of connection, an external connection and a sub-choice of SQL queries.

select account, paymentfrom Account as account left outer join account.payments as paymentwhere: currentUser in elements (account.holder.users) and PaymentStatus.UNPAID = isNull (payment.currentStatus.name, PaymentStatus.UNPAID) order by account.type.sortOrder , account.accountNumber, payment.dueDate For some databases, we need to abandon the (related) sub-options.

select account, paymentfrom Account as account join account.holder.users as user left outer join account.payments as paymentwhere: currentUser = user and PaymentStatus.UNPAID = isNull (payment.currentStatus.name, PaymentStatus.UNPAID) order by account.type. sortOrder, account.accountNumber, payment.dueDate15.13. batches UPDATE & DELETE Statements
HQL now supports UPDATE and DELETE statements. Search section 14.3, "bulk update / delete (Bulk update / delete)" for more information.

15.14. Tips & tricks you can statistics on the number of query results without actually return them:

((Integer) session.iterate ( "select count (*) from ...."). next ()). IntValue () If you want to set the size according to a sort, you can use the following statement:

select usr.id, usr.namefrom User as usr left join usr.messages as msggroup by usr.id, usr.nameorder by count (msg) If your database supports sub-option, you can in your query where clause for selecting the size of the (selection size) to specify a condition:

from User usr where size (usr.messages)> = 1 If your database does not support the sub-select statement, use the following query:

select usr.id, usr.namefrom User usr.name join usr.messages msggroup by usr.id, usr.namehaving count (msg)> = 1 since their connection (inner join) the reasons, this solution can not return contain zero User information, an instance of the class, so this case, use the following format will be helpful:

select usr.id, usr.namefrom User as usr left join usr.messages as msggroup by usr.id, usr.namehaving count (msg) = 0JavaBean properties can be bound to a named query (named query) parameters: the

Query q = s.createQuery ( "from foo Foo as foo where foo.name =: name and foo.size =: size"); q.setProperties (fooBean); / / fooBean with methods getName () and getSize () List foos = q.list (); by Query interface with a filter (filter) used together collections (Collections) can be paged:

Query q = s.createFilter (collection, ""); / / a simple filter q.setMaxResults (PAGE_SIZE); q.setFirstResult (PAGE_SIZE * pageNumber); List page = q.list (); by using a query filter (query filter) can be a collection (Collection) of the elements grouped or sorted:

Collection orderedCollection = s.filter (collection, "order by this.amount"); Collection counts = s.filter (collection, "select this.type, count (this) group by this.type"); not through the initialization , you can know that a collection (Collection) size:

((Integer) session.iterate ( "select count (*) from ...."). next ()). IntValue ();

This article comes from CSDN blog, reproduced please indicate source: http://blog.csdn.net/gs192313/archive/2008/09/27/2989438.aspx

相关文章
  • HQL statement Daquan (change) 2010-03-29

    Hibernate is equipped with a very powerful query language that looks very much like SQL. But do not be grammatical structure of the confusing similarity, HQL is very conscious of is designed to be fully object-oriented queries, it can understand conc

  • Hibernate HQL statement (1) 2009-11-23

    HQL Definition HQL is Hibernate Query Lanaguage's shorthand, that hibernate query language: HQLhibernate. HQL queries using object-oriented way. HQL queries provide a more rich and flexible query features, so Hibernate will HQL query approach establi

  • Database Basic ---- SQL statement Daquan 2010-04-17

    Database Basic ---- SQL statement Daquan Society of the database is very useful D ~ ~ record number of commonly used sql statements ... have started to improve there have never seen the ... well ... the whole collection under the ... In fact, is gene

  • Hibernate HQL statement in the general pattern of 2010-07-14

    The past two days to write a lot of HQL statement, sum up all four steps in this four-step basis with the other processing logic on the line. Direct look at the code it: public static List<Integer> getAbsOperationIDsByServiceID(int sid){ List<Int

  • hql statement examples and detailed explanations (Reprinted) 2010-08-26

    HQL query HQL query: Criteria queries conducted on the query object-oriented package with programmers way of thinking, but the HQL (Hibernate Query Lanaguage) queries to provide a more rich and flexible query characteristics, Hibernate HQL query appr

  • hql statement in alternative methods and limit operation 2011-07-20

    If you want to search in MySql in the preceding articles, a collection of records, use limit, such as: SELECT * FROM tv_favorite t order by t.createtime limit 10; We use the DAO layer HQL statement, HQL syntax check does not identify the limit of. Be

  • 5 kinds of database sql statement Daquan 2011-05-10

    Database sql statement Daquan First, connect the column values db2/oracle/postgresql select name (field) | | 'Works AS a' (text) | | job as msg from emp where deptno = 10; mysql select concat (name, 'works as a', job) as msg from emp where deptno = 1

  • MySQL syntax statement Daquan 2010-09-03

    Daquan a MySQL syntax statement, SQL intensive structured query language (SQL) is the standard for relational database query language, which includes the same number of keywords and syntax, ease of database elements (such as tables, indexes, fields,

  • Classic SQL statement Daquan 2010-06-18

    A basic 1, Description: Create a database CREATE DATABASE database-name 2, Description: delete the database drop database dbname 3, Description: backup sql server --- Create a backup of the data device USE master EXEC sp_addumpdevice 'disk', 'testBac

  • SQL statement Daquan 2010-06-23

    Basis Create Database Create the database before the judge whether there if exists (select * from sysdatabases where name = 'databaseName') drop database 'databaseName' go Create DATABASE database-name Delete Database drop database dbname Backup sql

  • Oracle statement Daquan 2010-06-25

    1. Oracle installation is complete, the initial password? internal / oracle sys / change_on_install system / manager scott / tiger sysman / oem_temp 2. ORACLE9IAS WEB CACHE initial default user and password? administrator / administrator 3. Oracle 8.

  • MySQL statement Daquan 2010-11-10

    One. Connection mysql. Format : mysql -h Host address-u username -p Password 1. Connected to the unit on MYSQL. First, open the DOS window , Then enter the directory mysql\bin, Then type the command mysql-u root-p, enter the password after the prompt

  • Classic SQL statement Daquan (2) 2011-07-13

    Data development - the classic 1 in alphabetical order: Select * From TableName Order By CustomerName Collate Chinese_PRC_Stroke_ci_as / / from less to more (2) Database Encryption: select encrypt ('original password') select pwdencrypt ('original pa

  • Classic SQL statement Daquan: I. basic 2010-08-26

    1, Description: Create a database CREATE DATABASE database-name 2, Description: Removes database drop database dbname 3, Description: sql server backup --- Create a backup device data USE master EXEC sp_addumpdevice 'disk', 'testBack', 'c: \ mssql7ba

  • Classic SQL statement Daquan: three. Skills 2010-08-26

    1,1 = 1,1 = 2, use the SQL statement when combined with the more "Where 1 = 1" to indicate Select All "where 1 = 2" all the non-election, Such as: if @ strWhere! ='' begin set @ strSQL = 'select count (*) as Total from [' + @ tblName +

  • Classic SQL statement Daquan: six. SQLServer2000 replication technology steps 2010-08-26

    First, the preparatory work 1 release, Subscribers have the same name to create a windows user, and set the same password as a valid release snapshot folder access to the user - Management Tools - Computer Management - Users and Groups - Right-user -

  • SQL statement Daquan (rpm) 2011-05-16

    Original Address: http://topic.csdn.net/u/20110512/14/ac563ffc-e973-40ec-84ba-e655494fa405.html - Statement function - Data manipulation SELECT - retrieve data from the database table rows and columns INSERT - add new data to the database table row D

  • sql on the field or table CRUD, sql statement Daquan 2011-08-17

    1. Increase the field alter table docdsp add dspcode char (200) 2 Remove the field ALTER TABLE table_NAME DROP COLUMN column_NAME 3. Modify field types ALTER TABLE table_name ALTER COLUMN column_name new_data_type 4.sp_rename renamed EXEC sp_rename '

  • SqlServer 2005 statement Daquan 2011-09-28

    First, the basic 1, Description: Create a database Create DATABASE database-name 2, Description: Removes database drop database dbname 3, Description: sql server backup --- Create a backup device data USE master EXEC sp_addumpdevice 'disk', 'testBack

  • Described the relatively good access to the article: java in the PreparedStatement and Statement different (change) 2010-03-20

    First: Sql statement in the implementation of the database when the statement would be that if you use PreparedStatement advantage: Because the database will preparedStatement Statement pre-compiled, the next perform the same sql statement, the datab