刚刚接触数据库我们大都听过查询 增加 插入 删除这4大语句吧!
create database 数据库名字(创建数据库),create table 表名字(表的信息) (创建表)
他们分别是:
select (你要查找的列名分别用“逗号”隔开) from (表名)
例如:select name,email from userinfo
当用到多条件查询时 我们会用where 把我们需要限制的条件写在where 后面
例如:select name,email,address from userinfo where address='中国上海浦东区'
select name,email,address from userinfo where address like '中国上海%' (模糊查询)
select '亲爱的用户'+name+':您好,欢迎您!' from userinfo where address like '%上海%'(字段拼接)
select '亲爱的用户'+name+':您好,欢迎您!' as '活动注意事项' from userinfo where address like '%上海%'(使用别名更改列标题)
select name,email,address from userinfo where name like '——'(通配符找出用户名为2个字的用户信息)
select * from category where descn is null (使用null语句查询)
select name,price from product where (price between '50' and '200')(确定范围查询)
select name,price from product where price<100 order by 单价 asc (顺序排序/降序排序 desc)
select * from product order by name desc, supplier (按多属性值排序)
select distinct supplier as 供应商 from product order by supplier (消除重复查询)
select top 7* from product order by price desc (top n 查询)
select convert (char(10),getdate(),102)+'统计', * from product where name='足球'
(getdate()获取当前日期,102 显示的格式)
update (表名) set (要更新的内容用“逗号”隔开)
例如:update userinfo set password='123456',email='liduan1981@126.com' where id=1
delete from (表名)
例如:delete from userinfo where name='张飞'
由于会有主外键的约束所以删除时要注意。
insert into userinfo (要插入的内容用“逗号”隔开) values (对应插入的值也用“逗号”隔开)
例如:insert into userinfo (password,name,email,createdate) values('123456','李端','liduan1981@126.com' ,'2010-7-19')