一些基本的SQL命令
--显示版本号,当前日期
SELECT VERSION(),CURRENT_DATE(),NOW();
--免费的计算器
SELECT (20+5)*4 AS RESULT,SIN(PI()/3);
--创建数据库
CREATE DATABASE databasename;
--删除数据库
DROP DATABASE databasename;
--显示当前存在的数据库
SHOW DATABASES;
--选择数据库
USE databasename;
--显示当前选择的数据库
SELECT DATABASE(), USER();
--显示当前数据库中的表
SHOW TABLES;
--插入表
CREATE TABLE tablename
(
id varchar(32) not null primary key,
name varchar(20) not null,
password varchar(20) not null
);
--插入数据
INSERT INTO tablename VALUES ('CZX','Christen','litejava');
--导入脚本
SOURCE filepath; -- eg SOURCE C:/blog.sql
--删除表
DROP TABLE tablename;
--删除表中的全部数据
DELETE from tablename;
--更新数据
UPDATE tablename SET password='123456';
--显示表的内容
SELECT * from tablename;
--描述表的结构
DESCRIBE tablename;
--从文本中导入数据
LOAD DATA LOCAL INFILE 'file path' INTO TABLE tablename;
--选择特殊行
SELECT * from tablename WHERE id = 'czx';
SELECT name,password from tablename WHERE id = 'czx' AND name = 'Christen'
SELECT * from tablename WHERE name IS NULL;
--去除重复行
SELECT DISTINCT name from tablename;
--模糊查询
SELECT * from tablename WHERE name LIKE '%陈自新%';
--计数
SELECT COUNT(*) from tablename;
#按条件过滤
SELECT * from T_Employee WHERE FSalary>4000 AND FSalary<8000
SELECT * from T_Employee WHERE FSalary BETWEEN 4000 AND 8000
#排序asc升序,desc降序
#select * from info order by wage desc
#select * from info order by name asc
#模糊查询
#SELECT address from info where t_name like '%c%'
#插入一列
#alter table info add t_phone varchar(24) null
#求和sum,max,min,avg
#select sum(c_2) from tablename
显示数据库或表:
show databases;
use database_name;
show tables;
更改表名:
&
相关文档:
原网站无法访问,故保留google快照
How things work :
SQL
Select
Statement
Introduction
:
Ever asked your self how things work inside the
SQL
Select
statement? In this article we won’t be talking about how to writeSQL
Select
statem ......
Google dorks sql injection:
inurl:index.php?id=
inurl:trainers.php?id=
inurl:buy.php?category=
inurl:article.php?ID=
inurl:Play_old.php?id=
inurl:declaration_more.php?decl_id=
inurl:Pageid=
inurl:game ......
I'm continually trying to track down what service packs are installed on various SQL Servers I support. I can never find the right support page on Microsoft's site. So here's an article with all the SQL Server version information I can track down. If you know of any older versions or can help me fil ......
-- FUN:存储过程分页
-- @Table nvarchar(255), -- 表名
-- @Fields nvarchar(1000) = ' * ', -- 需要返回的列
-- @OrderField nvarchar(255), -- 排序的字段名,一般为唯一标识
-- @OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
-- @PageSize int = 10, -- 每页有多少条记录
-- @PageIndex int = 1, -- 第 ......
应一个朋友的要求,贴上收藏的SQL常用分页的办法~~
表中主键必须为标识列,[ID] int IDENTITY (1,1)
1.分页方案一:(利用Not In和SELECT TOP分页)
语句形式:
SELECT TOP 页记录数量 *
from 表名
WHERE (ID NOT IN
(SELECT TOP (每页行数*(页数-1)) ID
from 表名
ORDER BY ......