基础
创建数据库
创建之前判断该数据库是否存在
if exists (select * from sysdatabases where name='databaseName')
drop database databaseName
go
Create DATABASE database-name
删除数据库
drop database dbname
备份 sql server
--- 创建 备份数据的 device
USE master
EXEC sp_addumpdevice 'disk', 'testBack',
'c:\mssql7backup\MyNwind_1.dat'
--- 开始 备份
BACKUP DATABASE pubs TO testBack
创建新表
create table tabname(col1 type1 [not null] [primary key],col2
type2 [not null],..)
根据已有的表创建新表:
A:go
use 原数据库名
go
select * into 目的数据库名.dbo.目的表名 from 原表名(使用旧表创建
新表)
B:create table tab_new as select col1,col2… from tab_old
definition only
创建序列
create sequence SIMON_SEQUENCE
minvalue 1 -- 最小值