首页 > 代码库 > 数据库编程
数据库编程
结构化查询语言SQL
1.创建表格
create table tablename
(column1 datatype [constraint],
column2 datatype [constraint],
column3 datatype [constraint]);
例
create table employee
(firstname varchar(15),
lastname varchar(20),
age int,
address varchar(30),
city varchar(20));
2 删除数据库表格——注意,这里不要胡记成"delete",那么,为什么delete不用呢,原来,其被用到了删除数据
drop table tablename
例
drop table employee;
3 数据查询
select column1 [, column2,etc] from tablename
[where condition];
[order by counmn1[ASC|DESC] [,order by column2[ASC|DESC]]]
例如:
1)select * from employee;
2)select firstname,lastname from employee;
3)select firstname,lastname from employee where age>30;
4 向表中插入数据
insert into tablename
(first_column,...last_column)
values (first_value,...last_value);
例如:
insert into employee
(firstname, lastname, age, address, city)
values (‘Wu’, ‘Jun’, 20, ‘No.11 Beijing Road’, ‘Wuhan’);
5 更新数据
update tablename
set columnname = newvalue [, nextcolumn = newvalue2...]
where columnname OPERATOR value [and|or column OPERATOR value];
例如:
update employee
set age = age+10
where firstname= ‘Li’and lastname= ‘Ming’;
6 删除数据
delete from tablename
where columnname OPERATOR value [and|or column OPERATOR value];
例如:
delete from employee
where firstname=‘Wu’ and lastname = ‘Jun’;
数据库编程