SQL的一些基本操作语法
2013-03-11 12:01
681 查看
创建数据库:create DataBase 数据库的名字
创建表:
create table 表名
(
字段 类型 [约束]
字段 类型 [约束]
)
创建约束:
->建约束
alter table test add constraint PK_text_column primary key(_column) --主键约束
alter table test add constraint DK_text_column default(_value) for _column --默认约束
alter table test add constraint CK_test_column check(sex='男'or sex='女') --检查约束
alter table test add constraint UQ_test_column unique(_column) --唯一约束
alter table test1 add constraint FK_test1_test2_column foreign key (_column1) references
增
insert into 表名(字段名) values ('1','2','3','4')
select _column into _table_new from _table_old --要求表是存在的
insert into _table_new select * from _table_old --要求表是不存在的
删
delete from 表名 where 条件
truncate table 表名;--所以有数据归零
drop table _table
drop database _database
改
update 表名 set _column = _values,_column = _values where condition
查
->from 字句
->where字句
->group by 子句
->having 子句
->select top distinct
->order by
表与表的连接
->交叉连接
select * from _table1 cross join _table2;
->内连接
select * from _table1 inner join _table2 on ID=ID
->外联接
select * from _table1 left join _table2 on ID=ID
->自连接、多表连接
表join表on。。。join表on。。。
创建分页的存储过程
create proc 存储过程的名字
@pageIndex int=1, --页码(这里设置了默认值,也可以不用设置)
@pageSize int =5 ---页容量
as
select * from
(select ROW_NUMBER() over (order by stuid) as num,* from Student ) as temp
where num between (@pageIndex-1)*@pageSize+1 and @pageIndex*@pageSize
创建表:
create table 表名
(
字段 类型 [约束]
字段 类型 [约束]
)
创建约束:
->建约束
alter table test add constraint PK_text_column primary key(_column) --主键约束
alter table test add constraint DK_text_column default(_value) for _column --默认约束
alter table test add constraint CK_test_column check(sex='男'or sex='女') --检查约束
alter table test add constraint UQ_test_column unique(_column) --唯一约束
alter table test1 add constraint FK_test1_test2_column foreign key (_column1) references
增
insert into 表名(字段名) values ('1','2','3','4')
select _column into _table_new from _table_old --要求表是存在的
insert into _table_new select * from _table_old --要求表是不存在的
删
delete from 表名 where 条件
truncate table 表名;--所以有数据归零
drop table _table
drop database _database
改
update 表名 set _column = _values,_column = _values where condition
查
->from 字句
->where字句
->group by 子句
->having 子句
->select top distinct
->order by
表与表的连接
->交叉连接
select * from _table1 cross join _table2;
->内连接
select * from _table1 inner join _table2 on ID=ID
->外联接
select * from _table1 left join _table2 on ID=ID
->自连接、多表连接
表join表on。。。join表on。。。
创建分页的存储过程
create proc 存储过程的名字
@pageIndex int=1, --页码(这里设置了默认值,也可以不用设置)
@pageSize int =5 ---页容量
as
select * from
(select ROW_NUMBER() over (order by stuid) as num,* from Student ) as temp
where num between (@pageIndex-1)*@pageSize+1 and @pageIndex*@pageSize
相关文章推荐
- 用SQL语句添加删除修改字段、一些表与字段的基本操作、数据库备份等
- 用SQL语句添加删除修改字段、一些表与字段的基本操作、数据库备份等
- 用SQL语句添加删除修改字段、一些表与字段的基本操作、数据库备份等
- SQL里面脚本的一些基本的操作
- MYSQL常用命令与SQL基本语法(重要操作汇总)
- Sql Server实用操作-动态sql语句基本语法
- win7系统SQLServer2008 基本操作和sqlcmd 实用语法
- 一些基本sql操作
- 用SQL语句添加删除修改字段、一些表与字段的基本操作、数据库备份等,需要的朋友可以参考下。
- SQL 的一些基本操作
- SQL语句的基本常用的一些语法
- Sql Server实用操作-动态sql语句基本语法
- 用SQL语句添加删除修改字段、一些表与字段的基本操作、数据库备份等,需要的朋友可以参考下。
- 用SQL语句添加删除修改字段、一些表与字段的基本操作、数据库备份等
- sql的一些基本操作
- sql一些基本操作
- 【数据库】 sql的一些基本语法(三)
- 对数据库中列的一些基本的操作的SQL命令
- 用SQL语句添加删除修改字段、一些表与字段的基本操作、数据库备份等
- 用SQL语句添加删除修改字段和一些其他基本操作------阿冬专栏