SQL Server 几个好用的SQL语句
SQL Server 几个好用的SQL语句
1、复制表
select * into desttable from srctable
将 srctable 完整地复制一份到 desttable 中,当然后面也可以加上条件来限定需要复制的记录
要求:desttable 必须为不存在的表名。
insert into desttable(column1, column2) select columna, columnb from srctable
将 srctable 表中的columna, columnb 字段制到 desttable 的column1, column2中,后面也可以加上条件来限定需要复制的记录
要求:desttable 必须为已经存在的表名。
2、连接修改、删除语句
delete from table1 from table1 inner join table2 on table1.id = table2.tid
表的连接删除语句
update table1 set table1.column1 = table2.columna, table1.column2 = table2.columnb
from table1 inner join table2 on table1.id = table2.id
表的连接更新语句,使用起来非常方便。
相关文档:
如果你经常遇到下面的问题,你就要考虑使用SQL Server的模板来写规范的SQL语句了:
SQL初学者。
经常忘记常用的DML或是DDL SQL 语句。
在多人开发维护的SQL中,每个人都有自己的SQL习惯,没有一套统一的规范。
在SQL Server Management Studio中,已经给大家提供了很多常用的现成SQL规范模板。
SQL Server Management ......
--SQL高级程序设计:子查询
use AdventureWorks
GO
SELECT DISTINCT EmployeeID from HumanResources.JobCandidate WHERE EmployeeID IS NOT NULL;
SELECT e.EmployeeID,FirstName,LastName
from HumanResources.Employee e
INNER JOIN Person.Contact c
ON e.ContactID = c.ContactID
WHERE e.EmployeeID IN ......
<%
Dim Fy_Url,Fy_a,Fy_x,Fy_Cs(),Fy_Cl,Fy_Ts,Fy_Zx
'---定义部份 头------
Fy_Cl = 1 '处理方式:1=提示信息,2=转向页面,3=先提示再转向
Fy_Zx = "Error.Asp" '出错时转向的页面
'---定义部份 尾------
On Error Resume Next
Fy_Url=Request.ServerVariables("QUER ......
今天在网上上看见一篇“将SQL查询结果转化为pojo对象的”博客,博主自定义做了一个类如下:
import java.lang.reflect.Field;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.property.ChainedPropertyAccessor;&n ......
如果temp_t1不存在,
oracle:
create table temp_t1
as
select * from t1
sql server:
select * into temp_t1 from t1
如果temp_t1存在,
oracle:
insert into table temp_t1
select * from t1
sql server:
insert into table temp_t1
select * from t1 ......