下载此文档

软件开发.pdf


文档分类:IT计算机 | 页数:约12页 举报非法文档有奖
1/12
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/12 下载此文档
文档列表 文档介绍
Sql Server 里常用的基础 Sql 语句
Create Database
创建数据库
create database TestDB
Drop Database
删除数据库
drop database TestDB
Create Table
创建一个有主键的表
create table Department
(
DepartmentId int not null primary key,
CompanyId int,
DepartmentName nchar (20),
DepartmentInfo nchar (30)
)
创建一个有主键且非空且自增的表
create table People (
PersonId int identity (1,1) not null primary key,
DepartmentId int references Department (DepartmentId ),
PersonName nchar (30) check (PersonName
in('alephsoul' ,'shao' ,'xian' )),
PersonPassword nchar (30) default ('123456' ),
PersonInfo nchar (30),
)
Alter Table
为表添加一列
alter table People add PersonHome nchar (30)
删除表的一列
alter table pany drop panyId
为表设置主键
alter table pany add constraint priConstraint primary
panyId )
修改表列类型
alter table People alter column PersonName nchar (40) not null
为表添加外键
alter table People add foreign key(DepartmentId ) references
Department (DepartmentId )
Froeign Key
创建一个带有外键的表
create table People (
……
DepartmentId int references Department (DepartmentId ),
……
)
Select
选取表中所有记录
select * from people
获得 PersonId 列记录数
select COUNT (PersonId ) from people
获得记录总数
select COUNT (*) from people
获得首十个记录
select top 10 * from people
获得前百分之 10 的记录
select top 10 percent * from people
下面是一篇博文
一、基础
1、说明:创建数据库
Create DATABASEdatabase-name
2、说明:删除数据库
drop database dbname
3、说明:备份 sql server
--- 创建备份数据的 device
USE master
EXEC sp_addumpdevice ‘disk‘, ‘testBack‘, ‘c:\mssql7backup\‘
--- 开始备份
BACKUP DATABASEpubs TO testBack
4、说明:创建新表
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
根据已有的表创建新表:
A:create table tab_new like tab_old (使用旧表创建新表)
B: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
注:列增加后将不能删除。 DB2 中列加上后数据类型也不能改变,唯一能改变的是增加
varchar 类型的长度。
7、说明:添加主键: Alter table tabname add primary key(col)
说明:删除主键

软件开发 来自淘豆网www.taodocs.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数12
  • 收藏数0 收藏
  • 顶次数0
  • 上传人zbfc1172
  • 文件大小0 KB
  • 时间2015-10-20