SQL 基础语句【表、约束、索引】
表专区
--
复制表及数据(从
userinfo
表复制到新表
b
select
*
into
b
from
UserInfo
--
获取当前数据库中的所有用户表
select * from sysobjects where xtype='U' and category=0
--
获取某一个表的所有字段
select name from syscolumns where id=object_id('表名')
约束专区
--
查询表
约束
exec
sp_helpconstraint
表名
--
添加外键约束
alter
table
表名
add
constraint
外键名
foreign
key
(
引用列名
)
references
被引用表名
(
列名
)
索引专区
----查找表中的索引
select
*
from
sysindexes
where
id
=
object_id
(
'
表名
'
)
exec
sp_helpindex
g_Account
-----
判断是否存在索引
select
*
from
sysindexes
where
name
=
'索引名
'
--创建索引
CREATE UNIQUE INDEX 索引名称
ON 表名称
(
列名称
)
相关文档:
if object_id('[tb]') is not null
drop table [tb]
go
create table [tb]([id] int,[col1] varchar(8),[col2] int)
insert [tb]
select 1,'河北省',0 union all
select 2,'邢台市',1 union all
select 3,'石家庄市',1 union all
select 4,'张家口市',1 union all
&n ......
标准顺序的 SQL 语句为:
Select 考生姓名, max(总成绩) as max总成绩
from tb_Grade
where 考生姓名 is not null
group by 考生姓名
having max(总成绩) > 600
order by max总成绩
在上面的示例中 SQL 语句的执行顺序如下:
(1). 首先执行 from 子句, 从 tb_G ......
网站:http://werysoft.com/
如果您必须管理环境中的多种类型的数据库服务器,则使用集中式工具调整所有数据库可能会比较方便。Werysoft 的 QweryBuilder 旨在为您提供此项功能。您可以使用它从同一 GUI 连接到 Microsoft SQL Server、Sybase ASE、SQL Anywhere 和 Oracle 实例,然后查看、创建、更新和删除数据库脚本、架 ......
http://weblogs.asp.net/scottgu/archive/2007/09/07/linq-to-sql-part-9-using-a-custom-linq-expression-with-the-lt-asp-linqdatasource-gt-control.aspx
1-9 parts are the most useful knowledge for you so far. ......