删掉索引脚本
1. sql server中 表中如何创建索引
if exists(select *from sys.objects where naem = 'newindex')
drop index newindex
create index
--===================================
竟然没有悬赏...唉...
那算了吧
我还是都告诉你吧..
看个示例
自己琢磨去:
--==============================================
use master
go
if db_id(N'zhangxu')is not null
drop database zhangxu
go
create database zhangxu
sp_helpdb zhangxu
use zhangxu
go
IF EXISTS (SELECT *FROM SYS.OBJECTS WHERE NAME = N'WORKER')
DROP TABLE WORKER
GO
create table worker
(
w_id int identity (1000,1) not null,
w_name Nvarchar(10) unique,
w_age SMALLINT CONSTRAINT CK_W_AGE CHECK(w_age>20 and w_age<150),
w_pay money DEFAULT 0,
CONSTRAINT PK_W_ID PRIMARY KEY(W_ID)
)
SELECT *FROM WORKER--用查询技术查看表信息
sp_help worker--利用存储过程查看表信息
/*
创建简单的非聚集索引
*/
USE ZHANGXU
GO
if exists(select name from sys.indexes where name = N'IX_ID_NAME')
DROP INDEX IX_ID_NAME on worker
go--检查是否存在索引,有则删除索引
create index IX_ID_NAME--创建索引
on worker(w_id,w_name)--在ID NAME 两个字段上创建非聚集索引
drop index worker.IX_ID_NAME--删除索引
select *from sys.indexes where name = 'IX_ID_NAME'--查看索引
/*
创建唯一非聚集索引
*/
USE ZHANGXU
GO
IF EXISTS(SELECT NAME FROM SYS.INDEXES WHERE NAME = N'IX_W_NAME')
DROP INDEX IX_W_NAME ON WORKER
GO
CREATE UNIQUE INDEX IX_W_NAME--唯一非聚集索引
ON WORKER(W_NAME)
/*
查看索引T-SQL脚本
*/
--IX_W_NAME 唯一 非聚集索引
USE [zhangxu]
GO
/****** 对象: Index [IX_W_NAME] 脚本日期: 07/29/2007 16:54:53 ******/
CREATE UNIQUE NONCLUSTERED INDEX [IX_W_NAME] ON [dbo].[worker]
(
[w_name] ASC
)
WITH
(
SORT_IN_TEMPDB = OFF,
DROP_EXISTING = OFF,
IGNORE_DUP_KEY = OFF,
ONLINE = OFF
)
ON [PRIMARY]
--PK_W_ID聚集索引
USE [zhangxu]
GO
/****** 对象: Index [PK_W_ID] 脚本日期: 07/29/2007 16:56:45 ******/
ALTER TABLE [dbo].[worker]
ADD CONSTRAINT [PK_W_ID] PRIMARY KEY CLUSTERED
(
[w_id] ASC
)
WITH
(
SORT_IN_TEMPDB = OFF,
IGNORE_DUP_KEY = OFF,
ONLINE = OFF
) ON [PRIMARY]
--UQ_WORKER 唯一,非聚集索引
USE [zhangxu]
GO
/****** 对象: Index [UQ__worker__07020F21] 脚本日期: 07/29/2007 16:58:38 ******/
ALTER TABLE [dbo].[worker]
ADD UNIQUE NONCLUSTERED
(
[w_name] ASC
)
WITH
(SORT_IN_TEMPDB = OFF,
IGNORE_DUP_KEY = OFF,
ONLINE = OFF
) ON [PRIMARY]
select *from worker
insert into worker(w_name,w_age,w_pay) values('王国龙',25,4500)
2. 搜集SQL常用的操作语句
结构化查询语言(Structured Query Language)简称SQL(发音:/ˈes kjuː ˈel/ "S-Q-L"),是一种特殊目的的编程语言,是一种数据库查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统;同时也是数据库脚本文件的扩展名。
一、插入(复制)表数据
1、INSERT INTO 语句:
(1)插入新的一行数
[sql] view plain ;
INSERT INTO Persons VALUES ('Gates', 'Bill', 'Xuanwumen 10', 'Beijing');
(2)在指定的列中插入数据
[sql] view plain ;
INSERT INTO Persons (LastName, Address) VALUES ('Wilson', 'Champs-Elysees');
2、SQL SELECT INTO 语句可用于创建表的备份复件
(1)在建表时复制所有数据
[sql] view plain ;
create table userinfo_new as select * from userinfo;
(2)在建表时复制部分数据
[sql] view plain ;
create table userinfo_new1 as select id,username from userinfo;
(3)在添加时复制所有数据
[sql] view plain ;
insert into userinfo_new select * from userinfo;
(4)在添加时复制部分数据
[sql] view plain ;
insert into userinfo_new(id,username) select id,username from userinfo;
二、修改表数据
Update 语句
(1)无条件更新
[sql] view plain ;
update userinfo set userpwd='111',email='[email protected]';
(2)有条件更新
[sql] view plain ;
update userinfo set userpwd='123456' where username='xxx';
三、删除表数据
1、DELETE 语句
(1)无条件删除
[sql]view plain;
daletefromuserinfo;
(2)有条件删除
[sql]view plain;
='yyy';
四、查询表数据
1、SELECT 语句:
(1)查询所有字段
[sql] view plain ;
select * from users;
(2)查询指定字段
[sql] view plain ;
select username,salary from users;
2、SELECT DISTINCT 语句
从 Company" 列中仅选取唯一不同的值,需要使用 SELECT DISTINCT 语句:
[sql] view plain ;
SELECT DISTINCT Company FROM Orders;