<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆心得

    記我所見,記我所想

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      34 Posts :: 0 Stories :: 16 Comments :: 0 Trackbacks

    create unique index stusno on student(sno); --創建索引

    create clustered index stuname on student(sname);-- 創建聚簇索引

    drop index student.stuname; -- 刪除索引

    alter table student add constraint PK1_ID primary key(sno);--修改表的sno為主鍵


    --創建表

    create table student (

    sno char(5) not null unique,

    sname char(20) unique,
    ssex? char(1),

    sage int,
    sdept char(15));


    --刪除表
    drop table student;

    ?

    ALTER TABLE student DROP CONSTRAINT unique? --沒有解決

    alter table student drop CONSTRAINT sname ;

    --建立WoolAdminName表
    create table WoolAdminName
    (
    ID int identity(1,1) not null,
    AdminName varchar(30) not null,
    pwd varchar(30) not null
    )
    --建立管理員WoolAdminName表約束
    go
    alter table WoolAdminName
    add constraint PK_ID primary key(ID)
    insert into WoolAdminName values('admin','admin')

    create table course(

    cno char(5) not null? primary key,

    sname char(20) ,

    cpno char(5) not null,

    ccredit int );


    create table sc(

    cno char(5),

    sno char(5),

    grade int,

    primary key(sno,cno)
    )

    select * from student;
    insert into student values('1','ren','m',20,'信息工程');
    insert into student values('2','xi','w',18,'公共管理');
    insert into student values('3','hai','m',22,'管理科學');
    insert into student values('4','hui','w','19','信息工程');

    select sname 姓名, 40-sage 年齡 from student;

    select sname 姓名, sage 年齡 from student where sage >=20;

    select sname 姓名, sage 年齡 from student group by sage having? max(sage) ;




    use test1;

    alter table student drop unique(sname);

    select sname,'Year of Birth:',2007-sage birthday,lower(sdept) from student;

    select * from student;

    select ssex from student;

    select distinct ssex from student;

    ?

    select * from student where sage =22;

    select * from student where sage <>22;

    select * from student where sage !=22;

    ?

    select * from student where sage>21;

    select * from student where sage !>21;


    --下邊的形式不對
    select * from student where sage not > 21;
    --上邊的形式不對 應改成下邊的形式

    select * from student where not sage? > 21;

    ?


    select * from student where sage between 19 and 21;-- between and

    select * from student where sage not between 19 and 21;--not between and

    select * from student where sage in (19,20,21);-- in

    select * from student where sage not in (19,20,21);-- not in


    select * from student where sname like 'h\_i'escape '\';?? -- like

    select * from student where sname not like 'h%'; -- not like

    select * from student where sname is null;? -- is null

    select * from student where sname is not null; -- is not null

    select * from student where sname like 'h%' and sage>20;--and

    select * from student where sname like '%i' or sage<20;-- or


    select * from student where sage in (19,20,21)order by sage desc;-- order by

    select * from student order by sdept desc,sage desc;--系按降序排列,同系中的按年齡降序排列


    select count(*) from student; -- 統計元組個數

    select count(*) from student where sage>20; -- 有條件統計元組個數

    select? count(distinct ssex) from student;-- 統計一列中 不重復的值的個數

    select? count(ssex) from student;--統計一列中值的個數

    select sum(sage) from student;-- 計算一列值的總和(此列必為數值型)

    select avg(sage) from student; -- 計算一列值的平均值

    select max(sage) from student; -- 求一列值的最大值

    select min(sage) from student; -- 求一列值的最小值

    select sno from sc group by sno having count(*)>=2;

    SELECT *
    FROM dbo.course INNER JOIN
    ????? dbo.sc ON dbo.course.cno = dbo.sc.cno INNER JOIN
    ????? dbo.student ON dbo.sc.sno = dbo.student.sno

    select student.*,sc.* from student,sc where student.sno=sc.sno;--等值連接

    select student.*,sc.* from student,sc;--廣義笛卡爾積


    --等值連接去掉重復的列就是自然連接
    select student.sno,sname,ssex,sage,sdept,cno,grade from student,sc where student.sno=sc.sno;


    --自連接


    select first.cno,second.cpno from course first,course second where first.cpno=second.cno;


    SELECT p1.pub_id,p2.pub_id,p1.pr_info
    FROM pub_info AS p1 INNER? pub_info AS p2
    ON DATALENGTH(p1.pr_info)=DATALENGTH(p2.pr_info)

    --外連接

    --join_type 指出連接類型,可分為三種:內連接、外連接和交叉連接。內連接(INNER JOIN)使用比
    --較運算符進行表間某(些)列數據的比較操作,并列出這些表中與連接條件相匹配的數據行。根據所使用
    --的比較方式不同,內連接又分為等值連接、自然連接和不等連接三種。
    --外--連接分為左外連接(LEFT OUTER JOIN或LEFT JOIN)、右外連接(RIGHT OUTER JOIN或RIGHT JOIN)
    --和全外連接(FULL OUTER JOIN或FULL JOIN)三種。與內連接不同的是,外連接不只列出與連接條件相匹
    --配的行,而是列出左表(左外連接時)、右表(右外連接時)或兩個表(全外連接時)中所有符合搜索條件的
    --數據行。
    --交叉連接(CROSS JOIN)沒有WHERE 子句,它返回連接表中所有數據行的笛卡爾積,其結果集合中的
    --數據行數等于第一個表中符合查詢條件的數據行數乘以第二個表中符合查詢條件的數據行數。
    --連接操作中的ON (join_condition) 子句指出連接條件,它由被連接表中的列和比較運算符、邏輯
    --運算符等構成。
    --無論哪種連接都不能對text、ntext和image數據類型列進行直接連接,但可以對這三種列進行間接
    --連接。-

    ?


    select student.sno,sname,ssex,sage,sdept,cno,grade from student,sc where student.sno=sc.sno *;--錯誤的寫法

    -- 右外連接
    select student.sno,sname,ssex,sage,sdept,cno,grade from student right join sc on student.sno=sc.sno ;


    --左外連接
    SELECT a.*,b.* FROM luntan LEFT JOIN usertable as b
    ON a.username=b.username


    --嵌套查詢

    use test1;
    select sno, sname from student? where sno in (
    ???
    ?select sno from sc where cno in

    ??(select cno from course where sname='數據結構')
    );


    select student.sno,student.sname from student, sc, course

    ?where student.sno=sc.sno and sc.cno=course.cno and course.sname='數據結構';


    select sname,sage,sdept from student where sage<any(select sage from student where sdept='信息工程');


    select sname,sage,sdept from student where sage<all(select sage from student where sdept='信息工程');

    --exists關鍵字

    select sname from student where exists (select * from sc where sno=student.sno and cno='1');

    select sname from student where not exists (select * from sc where sno=student.sno and cno='1');


    select * from course;

    insert into course values('1','語文','2','');


    insert into course values('2','數學','2','');


    insert into course values('3','英語','2','');


    insert into course values('4','c語言','2','');


    insert into course values('5','數據結構','2','');

    select * from sc;

    insert into sc values('1','1','');

    insert into sc values('1','2','');

    insert into sc values('2','2','');

    insert into sc values('2','1','');

    insert into sc values('3','3','');

    insert into sc values('5','3','');

    ?

    posted on 2007-08-22 15:05 源自有緣 閱讀(737) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 国产免费AV片在线观看播放| 亚洲欧美日韩自偷自拍| 国产日韩精品无码区免费专区国产 | xxxx日本免费| 久久久久亚洲AV无码观看| 99在线视频免费| 亚洲一级二级三级不卡| 2021在线永久免费视频| 亚洲国产成人精品无码一区二区| 1000部禁片黄的免费看| 亚洲色大18成人网站WWW在线播放 亚洲色大成WWW亚洲女子 | 亚洲av无码国产综合专区 | 亚洲性线免费观看视频成熟| 亚洲国产成人精品久久| 男人的好免费观看在线视频| 亚洲午夜精品久久久久久app| 国产高清在线免费| 一级**爱片免费视频| 亚洲高清专区日韩精品| 中文字幕在线免费| 99亚偷拍自图区亚洲| 国产精品免费看久久久久| 人人爽人人爽人人片A免费 | 久久亚洲精精品中文字幕| 男女免费观看在线爽爽爽视频 | 亚洲免费视频网站| 亚洲一区在线观看视频| 国产在线19禁免费观看| 国产又黄又爽胸又大免费视频| 亚洲avav天堂av在线不卡| 大地资源免费更新在线播放| 国产亚洲日韩在线a不卡| 国产亚洲一区二区精品| 国产一卡2卡3卡4卡2021免费观看 国产一卡2卡3卡4卡无卡免费视频 | 男性gay黄免费网站| 亚洲成色WWW久久网站| 大学生一级毛片免费看| 性生大片视频免费观看一级 | 亚洲毛片不卡av在线播放一区| 嫩草影院在线播放www免费观看| 日本亚洲精品色婷婷在线影院|