Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

sqlserver ÆÚÖп¼ÊÔÌâ

 create database DB
use DB
--רҵ±í
create table major
(spno char(5) not null primary key,
 spname varchar(20) not null,
 pno char(2) )
--ѧÉú±í
create table student
(sno char(7) not null primary key,
 sname varchar(20) not null,
 ssex char(2) not null,
 sage smalldatetime ,
 spno char(5) not null foreign key references major(spno),
 classid char(5),
 Inyear char(4) not null )
select datediff(yyyy,'1981-8-12',getdate())from student
--¿Î³Ì±í
create table course
(cno char(10) not null primary key,
cname varchar(20) not null,
credit smallint ,
tno char(3))
--Ñ¡¿Î±í
create table scourse
(sno char(7) not null foreign key references student(sno),
 cno char(10) not null foreign key references course(cno),
 Gmark numeric(4,1),
primary key(sno,cno))
//µÚÒ»Ìâ
select * from student where datediff(yyyy,sage,getdate()) between 25 and (select datediff(yyyy,sage,getdate()) from student  where sname='ÀîÓÂ')
//µÚ¶þÌâ
select sno,sname from student where sno in  (  select sno from scourse where cno=(select cno from course where cname='²Ù×÷ϵͳ'))
//µÚÈýÌâ
 
select sname from student where sno in (select distinct sno from scourse where cno not in('1'))
//µÚËÄÌâ
select sname,sno  from student where sno in(select sno from scourse group by sno having count(sno)=(select count(*) from course))
select student.sname,student.sno  from student where student.sno in(select scourse.sno from scourse group by scourse.sno having count(scourse.sno)=(select count(*) from course))
//µÚÎåÌâ
select sname from student where sno in (select sno from student where Inyear='1999') and sno in (select sno from scourse where Gmark is null) and spno in(select spno from major where spname='¼ÆËã»úÈí¼þ')
select student.sname from student where  student.sno in (select student.sno from student where student.Inyear='1999')   and student.sno in (select scourse.sno from scourse where


Ïà¹ØÎĵµ£º

SqlServerÖвéѯ10µ½20ÌõÖ®¼äµÄÊý¾Ý

 ²éѯnorthwindÊý¾Ý¿âÖÐordersÖеÄ10µ½20Ìõ¼Ç¼
select   top   10   *   from   orders
 where   orderid > ( select  max(orderid)  from  (select top 10 orderid  from  orders order by orderid) as t&nbs ......

SqlServer´óÅúÁ¿µ¼Èëµ¼³öÊý¾Ý

BULK INSERT
¡¡¡¡ÔÚSQL ServerÖУ¬BULK INSERTÊÇÓÃÀ´½«ÍⲿÎļþÒÔÒ»ÖÖÌض¨µÄ¸ñʽ¼ÓÔص½Êý¾Ý¿â±íµÄT-SQLÃüÁî¡£¸ÃÃüÁîʹ¿ª·¢ÈËÔ±Äܹ»Ö±½Ó½«Êý¾Ý¼ÓÔص½Êý¾Ý¿â±íÖУ¬¶ø²»ÐèҪʹÓÃÀàËÆÓÚIntegration ServicesÕâÑùµÄÍⲿ³ÌÐò¡£ËäÈ»BULK INSERT²»ÔÊÐí°üº¬Èκθ´ÔÓµÄÂß¼­»òת»»£¬µ«Äܹ»ÌṩÓë¸ñʽ»¯Ïà¹Øµ ......

SQLSERVERÐÞ¸´Ð¡ÖªÊ¶

ÔÚÓëÊý¾Ý¿â´ò½»µÀµÄ¹¤×÷ÖÐʱ³£»áÅöµ½Ò»Ð©Êý¾Ý¿âµÄ´íÎó£¬Õâ¾ÍÉæ¼°µ½ÁËÐÞ¸´µÄ¹ý³Ì£¬ÒÔÏÂ֪ʶµã¶¼ÊÇ´ÓÍøÉÏÊÕ¼¯¶øÀ´:
1¡¢dbcc checkdb
Õâ¸öÃüÁî¿ÖÅÂÊÇÎÒÃÇ×î³£ÓõÄÁË£¬´ø¼ì²éºÍÐÞ¸´¹¦ÄÜ
Óï·¨¸ñʽ£º
DBCC CHECKDB
[
[ ( database_name | database_id | 0
[ , NOINDEX
| , { REPAIR_ALLOW_DATA_LOS ......

sqlserver ÉÏ»úÁ·Ï°Ìâ

 create database db
use db
go
create table course
(
 sno varchar(20),
 cno int ,
 Gmark int
)
insert into course values('20071513115',1,80)
insert into course values('20071513114',2,80)
insert into course values('20071513113',3,80)
insert into course values('20071513 ......

DatetimeÏÔʾ·½Ê½SQLServer


½ñÌìÔÚдÊÓͼʱ£¬Óöµ½Òª°ÑDatetimeÀàÐÍתVarcharÀàÐÍ¡£ÒÔÇ°ÔÚORALCE¾ÍÈÝÒ×£¬Ö±½ÓToChar(getdate(),'yyyy-mm-dd')¡£ÔÚSQL Server 2005
select CONVERT(varchar, getdate(), 120 )
2004-09-12 11:06:08
select CONVERT(varchar(12) , getdate(), 111 )
2004/09/12
select CONVERT(varchar(12) , getdate(), 112 )
200 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ