SQL SERVER 2005 »ù±¾²éѯ£¨Á¬½Ó²éѯ£©
use AdventureWorks
GO
SELECT c.LastName from Person.Contact c;
SELECT * from HumanResources.Employee e
INNER JOIN HumanResources.Employee m
ON e.ManagerID = m.EmployeeID; n
SELECT ProductID,Name,ProductNumber,ReorderPoint
from Production.Product
where ProductID in( select ProductID from Production.Product where ProductID in (1,2,3) )
if EXISTS( select ProductID from Production.Product where ProductID in (1,2,3) )
PRINT 'TRUE'
ELSE
PRINT 'FALSE'
SELECT e.EmployeeID,ce.FirstName,ce.LastName
from HumanResources.Employee e
INNER JOIN HumanResources.Employee m
ON e.ManagerID = m.EmployeeID
INNER JOIN Person.Contact ce
ON e.ContactID = ce.ContactID
INNER JOIN Person.Contact cm
ON m.ContactID = cm.ContactID
WHERE cm.FirstName = 'Jo' and cm.LastName = 'Brown';
Select SalesOrderID,SUM(OrderQty) as sum
from Sales.SalesOrderDetail
where SalesOrderID between 43684 and 43686
group by SalesOrderID
having SUM(OrderQty) > 5
create table UserInfor
(
UserID int not null,
FirstName nvarchar(50),
LastName nvarchar(50)
)
GO
ALTER TABLE UserInfor
add primary key (UserID)
INSERT INTO UserInfor(UserID,FirstName,LastName)
SELECT e.EmployeeID,ce.FirstName,ce.LastName
from HumanResources.Employee e
INNER JOIN HumanResources.Employee m
ON e.ManagerID = m.EmployeeID
INNER JOIN Person.Contact ce
ON e.ContactID = ce.ContactID
INNER JOIN Person.Contact cm
ON m.ContactID = cm.ContactID
WHERE cm.FirstName = 'Jo' and cm.LastName = 'Brown';
declare @MyTable table
(
SalesOrderID int,
CustomerID int
)
INSERT INTO @MyTable(SalesOrderID,CustomerID)
select SalesOrderID,CustomerID
from AdventureWorks.Sales.SalesOrderHeader
where SalesOrderId between 50222 and 50225
select * from @MyTable
create table Shippers
(
ShipperID int identity not null primary key,
ShipperName varchar(30) not null,
Address varchar(20) not null,
Ïà¹ØÎĵµ£º
CHECK Ô¼Êø(CHECK Ô¼Êø:¶¨ÒåÁÐÖпɽÓÊܵÄÊý¾ÝÖµ¡£¿ÉÒÔ½« CHECK Ô¼ÊøÓ¦ÓÃÓÚ¶à¸öÁУ¬Ò²¿ÉÒÔ½«¶à¸ö CHECK Ô¼ÊøÓ¦ÓÃÓÚµ¥¸öÁС£µ±³ýȥij¸ö±íʱ£¬Ò²½«³ýÈ¥ CHECK Ô¼Êø¡£)Ö¸¶¨¿ÉÓɱíÖÐÒ»Áлò¶àÁнÓÊܵÄÊý¾ÝÖµ»ò¸ñʽ¡£ÀýÈ磬¿ÉÒÔÒªÇó authors ±íµÄ zip ÁÐÖ»ÔÊÐíÊäÈëÎåλÊýµÄÊý×ÖÏî¡£
¡¡¡¡
¡¡¡¡¿ÉÒÔΪһ¸ö±í¶¨ÒåÐí¶à CHECK Ô¼Êø¡£¿ ......
thunder:
1.MYSQLʵÏÖ
mysql> select * from user;
+----+----------+----------+-----------------+
| ID | username | password | email |
+----+----------+----------+-----------------+
| 1 | admin | admin &nb ......
l ÔÚ³ÌÐòÖÐÆ´½ÓSQLÃüÁî
¿ÉÊÇÈçºÎÔÚC#³ÌÐòÖÐÔËÐÐÄØ£¿ÎÒÃǼǵÃÔÚÆÕͨµÄSQL²éѯÖУ¬Ò»°ãÐèÒª°Ñ²éѯÓï¾ä¸³Öµ¸øSalCommand.CommandTextÊôÐÔ£¬ÕâÀïÒ²¾ÍÏñÆÕͨµÄSQL²éѯÓï¾äÒ»Ñù£¬½«ÕâЩÓï¾ä¸³¸øSqlCommand.CommandTextÊôÐÔ¼´¿É¡£Òª×¢ÒâµÄÒ»µãÊÇ£¬ÆäÖеÄ"GO"Óï¾ä±êÖ¾×ÅSQLÅú´¦ÀíµÄ½áÊø£¬±àдSQL½Å±¾ÊÇÐèÒªµÄ£¬µ«ÊÇÔÚÕâÀïÊDz ......
--²âÊÔÊý¾Ý
create table table1(AID int,NAME nvarchar(20))
create table table2 (BID int,NUMBER nvarchar(20))
insert into table1 select 1,'Tom' union all
select 2,'Jim'
insert into table2 select 1,20 union all
select 1,30
--º¯Êý
create function F_Str(@ID int)
returns nvarchar(100)
as
begin
......
1.´´½¨Êý¾Ý¿â
--exec xp_cmdshell 'mkdir d:\project'--µ÷ÓÃDOSÃüÁî´´½¨Îļþ¼Ð£¬Ê¹Óô˾äÐèÒªÆô¶¯SQLµÄÍâΧ¹¤¾ß
if exists(select * from sysdatabases where name='Êý¾Ý¿âÃû')
drop database Êý¾Ý¿âÃû
set nocount on ......