
那要看你用的是什么脚本与数据库了,不过大至都是想同的,这里给出一些比较常用的语法:
1、说明:创建数据库
CREATE
DATABASE
database-name
2、说明:删除数据库
drop
database
dbname
3、说明:备份sql
server
---
创建
备份数据的
device
USE
master
EXEC
sp_addumpdevice
'disk',
'testBack',
'c:\mssql7backup\MyNwind_1dat'
---
开始
备份
BACKUP
DATABASE
pubs
TO
testBack
4、说明:创建新表
create
table
tabname(col1
type1
[not
null]
[primary
key],col2
type2
[not
null],)
根据已有的表创建新表:
A:create
table
tab_new
like
tab_old
(使用旧表创建新表)
B:create
table
tab_new
as
select
col1,col2…
from
tab_old
definition
only
5、说明:
删除新表:drop
table
tabname
6、说明:
增加一个列:Alter
table
tabname
add
column
col
type
注:列增加后将不能删除。DB2中列加上后数据类型也不能改变,唯一能改变的是增加varchar类型的长度。
7、说明:
添加主键:Alter
table
tabname
add
primary
key(col)
说明:
删除主键:Alter
table
tabname
drop
primary
key(col)
8、说明:
创建索引:create
[unique]
index
idxname
on
tabname(col…)
删除索引:drop
index
idxname
注:索引是不可更改的,想更改必须删除重新建。
9、说明:
创建视图:create
view
viewname
as
select
statement
删除视图:drop
view
viewname
10、说明:几个简单的基本的sql语句
选择:select
from
table1
where
范围
插入:insert
into
table1(field1,field2)
values(value1,value2)
删除:delete
from
table1
where
范围
更新:update
table1
set
field1=value1
where
范围
查找:select
from
table1
where
field1
like
’%value1%’
---like的语法很精妙,查资料!
排序:select
from
table1
order
by
field1,field2
[desc]
总数:select
count
as
totalcount
from
table1
求和:select
sum(field1)
as
sumvalue
from
table1
平均:select
avg(field1)
as
avgvalue
from
table1
最大:select
max(field1)
as
maxvalue
from
table1
最小:select
min(field1)
as
minvalue
from
table1
--新建表
CREATE TABLE #t1(
n INT,
x VARCHAR(4)
)
---添加数据
insert into #t1 (n,x) values(1,'ff')
---修改数据
update #t1 set x='gg' where n=1
---删除数据
delete from #t1 where n=1
---删除表
DROP TABLE #t1
import javasql;
public class JDBCTest {
public static void main(String[] args){
// 驱动程序名
String driver = "commysqljdbcDriver";
// URL指向要访问的数据库名scutcs
String url = "jdbc:mysql://127001:3306/scutcs";
// MySQL配置时的用户名
String user = "root";
// MySQL配置时的密码
String password = "root";
try {
// 加载驱动程序
ClassforName(driver);
// 连续数据库
Connection conn = DriverManagergetConnection(url, user, password);
if(!connisClosed())
Systemoutprintln("Succeeded connecting to the Database!");
// statement用来执行SQL语句
Statement statement = conncreateStatement();
// 要执行的SQL语句
String sql = "select from student";
// 结果集
ResultSet rs = statementexecuteQuery(sql);
String name = null;
while(rsnext()) {
// 选择sname这列数据
name = rsgetString("sname");
// 首先使用ISO-8859-1字符集将name解码为字节序列并将结果存储新的字节数组中。
// 然后使用GB2312字符集解码指定的字节数组
name = new String(namegetBytes("ISO-8859-1"),"GB2312");
// 输出结果
Systemoutprintln(rsgetString("sno") + "\t" + name);
}
rsclose();
connclose();
} catch(ClassNotFoundException e) {
Systemoutprintln("Sorry,can`t find the Driver!");
eprintStackTrace();
} catch(SQLException e) {
eprintStackTrace();
} catch(Exception e) {
eprintStackTrace();
}
}
}
上面只是查询的例子,如果你需要增删改查,只需要改sql就行了,sql你可以自己试着写写,这种简单的sql十分简单跟英文差不多,如果你实在不想做我再帮你写,自己动手丰衣足食。。。另外,如果你想把找出来的东西放起来,那么你需要自己建个实体类(student)来放这些数据。。
以上就是关于网页制作中,怎么创建数据库的查询、删除、添加信息代码全部的内容,包括:网页制作中,怎么创建数据库的查询、删除、添加信息代码、怎样添加查询删除数据库,有哪些语句、java对pl sql数据库查询,增加,修改,删除 *** 作等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)