网上收集总结一下mssql( 部分)
2014-01-08 12:43
288 查看
1、创建数据库
2、删除数据库
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
drop database '数据库名'
3、备份sql server
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
4、创建新表
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
--根据已有的表创建新表:
--(使用旧表创建新表)
--方法一
create table tab_new like tab_old
--方法二(这个倒有个)
create table tab_new as select col1,col2 from tab_old definition only
5、删除新表
drop table tabname
6、增加一个列
Alter table tabname add column col type
7、添加主键: Alter table tabname add primary key(col)
删除主键: Alter table tabname drop primary key(col)
8、创建索引:create [unique] index idxname on tabname(col….)
删除索引:drop index idxname
注:索引是不可更改的,想更改必须删除重新建。
9、创建视图:create view viewname as select statement
删除视图:drop view viewname
10、几个简单的基本的sql语句
选择:select * from table1 where 范围
插入:insert into table1(field1,field2) values(value1,value2)
删除:delete from table1 where 范围
更新:update table1 set field1=value1 where 范围
查找:select * from table1 where field1 like ’%value1%’ ---like的语法很精妙,查资料!
排序:select * from table1 order by field1,field2 [desc]
总数:select count as totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1
2、删除数据库
create database '数据库名'
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
drop database '数据库名'
3、备份sql server
--- 创建 备份数据的 device USE master EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat' --- 开始 备份 BACKUP DATABASE pubs TO testBack
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
4、创建新表
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
--根据已有的表创建新表:
--(使用旧表创建新表)
--方法一
create table tab_new like tab_old
--方法二(这个倒有个)
create table tab_new as select col1,col2 from tab_old definition only
5、删除新表
drop table tabname
6、增加一个列
Alter table tabname add column col type
7、添加主键: Alter table tabname add primary key(col)
删除主键: Alter table tabname drop primary key(col)
8、创建索引:create [unique] index idxname on tabname(col….)
删除索引:drop index idxname
注:索引是不可更改的,想更改必须删除重新建。
9、创建视图:create view viewname as select statement
删除视图:drop view viewname
10、几个简单的基本的sql语句
选择:select * from table1 where 范围
插入:insert into table1(field1,field2) values(value1,value2)
删除:delete from table1 where 范围
更新:update table1 set field1=value1 where 范围
查找:select * from table1 where field1 like ’%value1%’ ---like的语法很精妙,查资料!
排序:select * from table1 order by field1,field2 [desc]
总数:select count as totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1
相关文章推荐
- 从网上看到一些文章,自己再总结一下,在学习编程中一些要点
- iphone技术总结, 在网上找到比较有用的东东,整合一下
- 收集网上资料,总结得出如何同时运行多个tomcat(模拟在不同域中运行网页)
- 闪客工具 收集一下网上有意思的方法
- VS2005 MFC C/C++ 操作excel【网上找了好多列子,都不合适,自己总结一下】
- 初学javascript,网上的资料收集一下
- 归纳总结一下帧frame 片slise nalu 宏块 场 这些概念之间的关系和部分细节的理解
- 搜索引擎免费登陆入口大全 收集网上资料总结
- ORACLE数据库的导入导出(网上看了无数教程,感觉不好用,自己便总结了一下)
- 关于一些博弈的模型总结,巴什博奕+威佐夫博奕+尼姆博奕+Fibonacci博弈+公平组合博弈。把网上 的一些资料总结了一下
- [db] 收集一下网上的数据库连接串
- 网上收集的网页清理浮动方法大全及经验总结
- 常用的一些类或接口--网上收集整理(部分)
- thinkphp uploadify ajax上传图片,网上很多有问题,我简单总结一下
- 到网上收集了一个“高大上”的CSS3登入表单和大家分享一下
- 网上收集的部分JS脚本
- 股票经验总结 2010.1.6 ,部分为网上Copy,见谅 :) !
- <iOS>iphone技术总结, 在网上找到比较有用的东东,整合一下
- 网上收集的以及自己总结的iOS开发技巧
- 总结一下网上可以得到的R语言资源