第一篇:如何判斷SQL語句是否執(zhí)行了?(本站推薦)
如何判斷SQL語句是否執(zhí)行了?
我們可以利用err對象來判斷:
sql=“insert into table(f1,f2)values('v1','v2')”
conn.execute sql
if err.number<>0 then
response.write “哎呀,出錯了:”& err.description err.clear else
response.write “OK”
end if
第二篇:SQL語句判斷數(shù)據(jù)庫、表、字段是否存在
SQL語句判斷數(shù)據(jù)庫、表、字段是否存在--判斷[TestDB]是否存在if exists(select 1 from master..sysdatabases where name='TestDB')
print 'TestDB存在'
else
print 'TestDB不存在'
--判斷表[TestTb]是否存在if exists(select * from TestDB..syscolumns where id=object_id('TestDB.dbo.TestTb'))print '表TestTb存在'
else
print '表TestTb不存在'
--判斷[TestDB]數(shù)據(jù)中[TestTb]表中是否存在[Name]字段
if exists(select * from TestDB..syscolumns where id=object_id('TestDB.dbo.TestTb')and name='Name')
print '字段Name存在'
else
print '字段Name不存在'
第三篇:sql常用語句
//創(chuàng)建臨時表空間
create temporary tablespace test_temp
tempfile 'E:oracleproduct10.2.0oradatatestservertest_temp01.dbf'size 32m
autoextend on
next 32m maxsize 2048m
extent management local;
//創(chuàng)建數(shù)據(jù)表空間
create tablespace test_data
logging
datafile 'E:oracleproduct10.2.0oradatatestservertest_data01.dbf'size 32m
autoextend on
next 32m maxsize 2048m
extent management local;
//創(chuàng)建用戶并指定表空間
create user username identified by password
default tablespace test_data
temporary tablespace test_temp;
//給用戶授予權(quán)限
//一般用戶
grant connect,resource to username;
//系統(tǒng)權(quán)限
grant connect,dba,resource to username
//創(chuàng)建用戶
create user user01 identified by u01
//建表
create table test7272(id number(10),name varchar2(20),age number(4),joindate date default sysdate,primary key(id));
//存儲過程
//數(shù)據(jù)庫連接池
數(shù)據(jù)庫連接池負(fù)責(zé)分配、管理和釋放數(shù)據(jù)庫連接
//
//創(chuàng)建表空間
create tablespace thirdspace
datafile 'C:/Program Files/Oracle/thirdspace.dbf' size 10mautoextend on;
//創(chuàng)建用戶
create user binbin
identified by binbin
default tablespace firstspace
temporary tablespace temp;
//賦予權(quán)限
GRANT CONNECT, SYSDBA, RESOURCE to binbin
//null與""的區(qū)別
簡單點(diǎn)說null表示還沒new出對象,就是還沒開辟空間
個對象裝的是空字符串。
//建視圖
create view viewname
as
sql
//建索引
create index indexname on tablename(columnname)
//在表中增加一列
alter table tablename add columnname columntype
//刪除一列
alter table tablename drop columnname
//刪除表格內(nèi)容,表格結(jié)構(gòu)不變
truncate table tableneme
//新增數(shù)據(jù)
insert into tablename()values()
//直接新增多條數(shù)據(jù)
insert into tablename()
selecte a,b,c
from tableabc
//更新數(shù)據(jù) new除了對象,但是這“”表示
update tablename set columnname=? where
//刪除數(shù)據(jù)
delete from tablename
where
//union語句
sql
union
sql
//case
case
when then
else
end
第四篇:SQL語句
SQL練習(xí)
一、設(shè)有如下的關(guān)系模式,試用SQL語句完成以下操作:
學(xué)生(學(xué)號,姓名,性別,年齡,所在系)
課程(課程號,課程名,學(xué)分,學(xué)期,學(xué)時)
選課(學(xué)號,課程號,成績)
1. 求選修了課程號為“C2”課的學(xué)生學(xué)號
2. 求選修了課程號為“C2”課的學(xué)生學(xué)號和姓名
3. 求沒有選修課程號為“C2”課的學(xué)生學(xué)號
4. 求選修了課程號為“C2”,又選修了課程號為“C3”課的學(xué)生學(xué)號
5.求選修了課程號為“C2”或“C3”課的學(xué)生學(xué)號
6.求選修了全部課程的學(xué)生學(xué)號
7.求至少選修了學(xué)號為“98002”的學(xué)生所學(xué)過的所有課程的學(xué)生的學(xué)號和姓名。
8.查詢學(xué)生選課表中的全部數(shù)據(jù)
9.查詢計算機(jī)系學(xué)生的姓名、年齡
10.查詢成績在70—80分之間的學(xué)生的學(xué)號、課程號和成績
11.查詢計算機(jī)系年齡在18—20之間且性別為“男”的學(xué)生的姓名和年齡
12.查詢成績在80分以上的學(xué)生的姓名、課程號和成績,并按成績的降序排列結(jié)果。
13.查詢哪些課程沒有人選修,要求列出課程號和課程名。
14.查詢數(shù)學(xué)系成績在80分以上的學(xué)生的學(xué)號,姓名
15.查詢課程號為“C02”的課程的最高分?jǐn)?shù)。
16.查詢計算機(jī)系學(xué)生的最大年齡和最小年齡。
17.統(tǒng)計每個系的學(xué)生人數(shù)。
18.統(tǒng)計每門課程的選課人數(shù)和考試最高分。
19.統(tǒng)計每個學(xué)生的選課門數(shù)和考試總成績,并按選課門數(shù)的升序顯示結(jié)果。
20.查詢總成績超過200分的學(xué)生,要求列出學(xué)號、總成績。
21.用子查詢實現(xiàn)如下查詢:
(1)查詢選修了課程號“C01”的學(xué)生的姓名和所在系。
(2)查詢數(shù)學(xué)系成績在80分以上的學(xué)生的學(xué)號和姓名。
(3)查詢計算機(jī)系考試成績最高的學(xué)生的姓名。
22.刪除選課成績小于60分的學(xué)生的選課記錄。
23.將所有選修了課程“C01”的學(xué)生的成績加10分。
24.將計算機(jī)系所有選修了課程“計算機(jī)文化基礎(chǔ)”課程的學(xué)生的成績加10分。
25.創(chuàng)建查詢學(xué)生的學(xué)號、姓名、所在系、課程號、課程名、課程學(xué)分的視圖。
26.創(chuàng)建查詢每個學(xué)生的平均成績的視圖,要求列出學(xué)生學(xué)號和平均成績。
27.創(chuàng)建查詢每個學(xué)生的選課學(xué)分的視圖,要求列出學(xué)生學(xué)號及總學(xué)分。
第五篇:SQL語句
SQL語句,用友的SQL2000,通過查詢管理器寫的語句
1、查詢
2、修改
3、刪除
4、插入
表名:users 包含字段:id,sname,sage
查詢 select * from users查詢users表中所有數(shù)據(jù)
select id,sname,sage from users查詢users表中id,sname,sage字段所有數(shù)據(jù)
可以限定查詢條件比如:
select sname from users where sage>20查詢年齡大于20歲的所有人的名字
修改 update users set sname='李四',sage=22將users表中數(shù)據(jù)都改為姓名李四,年齡22
update users set sname='李四',sage=22 where id=1限定id為1的人的信息修改為
姓名李四,年齡22
可以加where條件。
刪除 delete from users where id=2刪除users表中id為2的一行數(shù)據(jù)delete from users 代表刪除users中所有數(shù)據(jù)
插入 insert into users(id,sname,sage)values(5,'劉三',21)插入一條數(shù)據(jù)
SQL四條最基本的數(shù)據(jù)操作語句:Insert,Select,Update和Delete。
例如:SELECT columns FROM tables;其中columns為列的名稱,tables為表格名稱
1、查詢:select 字段名 from 表名 where 條件
查找在表(如A)中符合條件的字段
2、修改:update 表名 set 字段名=‘所要修改的內(nèi)容’
修改在表(如A)中的字段的值為:所要修改的內(nèi)容
3、刪除: delete from 表名 where 條件
刪除符合條件的表(如A)中的信息
4、插入: insert into 表名(字段名)(‘插入內(nèi)容’)
在表(如A)中插入字段為:插入內(nèi)容 的一條信息