四年300个攻击技术总结(2006-2009)
2010-08-26 09:10
246 查看
1、把主键定义为自动增长标识符类型
在mysql中,如果把表的主键设为auto_increment类型,数据库就会自动为主键赋值。例如:
create table customers(id int auto_increment primary key not null, name varchar(15));
insert into customers(name) values("name1"),("name2");
select id from customers;
以上sql语句先创建了customers表,然后插入两条记录,在插入时仅仅设定了name字段的值。最后查询表中id字段,查询结果为:
id
1
2
由此可见,一旦把id设为auto_increment类型,mysql数据库会自动按递增的方式为主键赋值。
在MS SQLServer中,如果把表的主键设为identity类型,数据库就会自动为主键赋值。例如:
create table customers(id intidentity(1,1) primary key not null, name varchar(15));
insert into customers(name) values("name1"),("name2");
select id from customers;
查询结果和mysql的一样。由此可见,一旦把id设为identity类型,MS SQLServer数据库会自动按递增的方式为主键赋值。identity包含两个参数,第一个参数表示起始值,第二个参数表示增量。
2、从序列中获取自动增长的标识符
在Oracle中,可以为每张表的主键创建一个单独的序列,然后从这个序列中获取自动增加的标识符,把它赋值给主键。例如一下语句创建了一个名为customer_id_seq的序列,这个序列的起始值为1,增量为2。
create sequence customer_id_seq increment by 2 start with 1
一旦定义了customer_id_seq序列,就可以访问序列的currval和nextval属性。
curval:返回序列的当前值
nextval:先增加序列的值,然后返回序列值
以下sql语句先创建了customers表,然后插入两条记录,在插入时设定了id和name字段的值,其中id字段的值来自于customer_id_seq序列。最后查询customers表中的id字段。
create table customers(id int primary key not null, name varchar(15));
insert into customers values(customer_id_seq.currval, "name1"),(customer_id_seq.nextval, "name2");
select id from customers;
如果在oracle中执行以上语句,查询结果为:
id
1
3
--在使用CURRVAL之前必须先使用NEXTVAL,select customer_id_seq.nextval from dual;
在mysql中,如果把表的主键设为auto_increment类型,数据库就会自动为主键赋值。例如:
create table customers(id int auto_increment primary key not null, name varchar(15));
insert into customers(name) values("name1"),("name2");
select id from customers;
以上sql语句先创建了customers表,然后插入两条记录,在插入时仅仅设定了name字段的值。最后查询表中id字段,查询结果为:
id
1
2
由此可见,一旦把id设为auto_increment类型,mysql数据库会自动按递增的方式为主键赋值。
在MS SQLServer中,如果把表的主键设为identity类型,数据库就会自动为主键赋值。例如:
create table customers(id intidentity(1,1) primary key not null, name varchar(15));
insert into customers(name) values("name1"),("name2");
select id from customers;
查询结果和mysql的一样。由此可见,一旦把id设为identity类型,MS SQLServer数据库会自动按递增的方式为主键赋值。identity包含两个参数,第一个参数表示起始值,第二个参数表示增量。
2、从序列中获取自动增长的标识符
在Oracle中,可以为每张表的主键创建一个单独的序列,然后从这个序列中获取自动增加的标识符,把它赋值给主键。例如一下语句创建了一个名为customer_id_seq的序列,这个序列的起始值为1,增量为2。
create sequence customer_id_seq increment by 2 start with 1
一旦定义了customer_id_seq序列,就可以访问序列的currval和nextval属性。
curval:返回序列的当前值
nextval:先增加序列的值,然后返回序列值
以下sql语句先创建了customers表,然后插入两条记录,在插入时设定了id和name字段的值,其中id字段的值来自于customer_id_seq序列。最后查询customers表中的id字段。
create table customers(id int primary key not null, name varchar(15));
insert into customers values(customer_id_seq.currval, "name1"),(customer_id_seq.nextval, "name2");
select id from customers;
如果在oracle中执行以上语句,查询结果为:
id
1
3
--在使用CURRVAL之前必须先使用NEXTVAL,select customer_id_seq.nextval from dual;
相关文章推荐
- 常见【十种】WEB攻击及防御技术总结
- 常见【十种】WEB攻击及防御技术总结
- 常见的WiFi攻击技术及检测方法总结
- 常见【十种】WEB攻击及防御技术总结
- 高级Mysql攻击技术(翻译blackhat 2009文章)
- 忆龙2009:检测IDS攻击的技术
- 忆龙2009:检测IDS攻击的技术
- 【MongoDB】索引技术总结
- 技术人才离职原因分析:一个技术管理者的总结
- TEC1303.Form个性化技术总结 - 第二部分 Form个性化开发实例
- CentOS技术(5)--mysql数据库常用命令总结
- 谈判专家应用的一些技术总结2 服务器后台的选择
- 反虚拟机技术总结
- webkit webApp 开发技术要点总结
- 技术面面试总结2
- 技术问题问答总结
- 【《Real-Time Rendering 3rd》 提炼总结】(五) 第六章 · 纹理贴图及相关技术 The Texturing
- java核心技术学习笔记(二)—基本数据类型总结