Sql_Server_和_Access_操作數(shù)據(jù)庫結(jié)構(gòu)的常用Sql_第1頁
Sql_Server_和_Access_操作數(shù)據(jù)庫結(jié)構(gòu)的常用Sql_第2頁
Sql_Server_和_Access_操作數(shù)據(jù)庫結(jié)構(gòu)的常用Sql_第3頁
Sql_Server_和_Access_操作數(shù)據(jù)庫結(jié)構(gòu)的常用Sql_第4頁
Sql_Server_和_Access_操作數(shù)據(jù)庫結(jié)構(gòu)的常用Sql_第5頁
已閱讀5頁,還剩1頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、下面是sql server 和 access 操作數(shù)據(jù)庫結(jié)構(gòu)的常用sql,希望對你有所幫助。新建表:create table 表名(自動編號字段 int identity (1,1) primary key ,字段1 nvarchar(50) default 默認值 null ,字段2 ntext null ,字段3 datetime,字段4 money null ,字段5 int default 0,字段6 decimal (12,4) default 0,字段7 image null ,)刪除表:drop table 表名插入數(shù)據(jù):insert into 表名 (字段1,字段2) valu

2、es (100,51windows.net)刪除數(shù)據(jù):delete from 表名 where 字段名100更新數(shù)據(jù):update 表名 set 字段1 = 200,字段2 = 51windows.net where 字段三 = haiwa新增字段:alter table 表名 add 字段名 nvarchar (50) null刪除字段:alter table 表名 drop column 字段名修改字段:alter table 表名 alter column 字段名 nvarchar (50) null重命名表:(access 重命名表,請參考文章:在access數(shù)據(jù)庫中重命名表)sp_r

3、ename 表名, 新表名, object新建約束:alter table 表名 add constraint 約束名 check (約束字段 80);(3)法二select sno, avg(grade) averagefrom scgroup by snohaving(avg(grade)80);(4)delete from sc where sc.sno in( select sno from s where sname=s5);(5)select snamefrom swhere sdept=英語and sex=男;(6)select sc.sno,avg(grade) as aver

4、agefrom s,scwhere s.sno=sc.snogroup by sc.sno;(7)select s.sname as 姓名 ,grade as 成績 ,c.cname as 選修課程from sc,s,cwhere s.sno=sc.sno and sc.cno=c.cno and sc.cno in( select cno from c where cname=db);(8)select top 1 sno as 學號,grade as 分數(shù),cname as 課程名from sc,cwhere sc.cno=c.cno and cname=osorder by grade

5、desc;(9)select snamefrom swhere not exists( select * from sc where sno=s.sno and cno=1);(10)select snamefrom swhere not exists( select * from c where not exists( select * from sc where sno=s.sno and cno=c.cno);(11)select distinct snofrom sc,scxwhere not exists( select * from sc scy where scy.sno=950

6、01 and not exists( select * from sc scz where scz.sno=scx.sno and scz.cno=scy.cno);(12)select top 3 cno as 課程號, snofrom scwhere cno=1order by grade desc;create database stu use stu create table s ( sno char(6), sname char(10), age int, sex char(2), constraint pk_s primary key (sno), constraint ck_age check(age=0 and age=0) ) create table sc ( sno char(6), cno char (8), constraint pk_sc primary key (sno,cno), constraint fk_s foreign key (sno) references s(sno), constraint fk_c foreign key (cno) re

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論