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 表名称
(
列名称
)
相关文档:
1修改基本表
添加列 alter table tableName add<新列名><数据类型>[完整性约束]
删除列 alter table tableName drop<新列名><数据类型>[完整性约束]
2创建
建表create table tableName(
id primary key AUTO_INCREMENT(mysql);
id primary key identity(1,1)(s ......
---- 人们在使用SQL时往往会陷入一个误区,即太关注于所得的结果是否正确,而忽略
了不同的实现方法之间可能存在的性能差异,这种性能差异在大型的或是复杂的数据库
环境中(如联机事务处理OLTP或决策支持系统DSS)中表现得尤为明显。笔者在工作实践
中发 ......
来源:http://www.cnblogs.com/jxnuxg/articles/1114418.html
CONVERT(data_type,expression[,style])
语句及查询结果:
SELECT CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM
SELECT CONVERT(varchar(100), GETDATE(), 1): 05/16/06
SELECT CONVERT(varchar(100), GETDATE(), 2): 06.05.16
SELECT CO ......
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Xml;
using System.Data;
namespace MyDbTest
{
class Program
{
static void Main(string[] args)
{
SqlConnection thisConnection = new SqlConnection(
@ ......