1.查询当前数据库所有表
复制代码 代码如下:
SELECT
O.object_id AS TableId,
TableName=O.name ,
TableDesc= O.type
FROM sys.columns C
INNER JOIN sys.objects O
ON C.[object_id]=O.[object_id]
AND O.type='U'
AND O.is_ms_shipped=0
INNER JOIN sys.types T
ON C.user_type_id=T.user_type_id
LEFT JOIN sys.extended_properties PTB
ON PTB.class=1
AND PTB.minor_id=0
AND C.[object_id]=PTB.major_id
WHERE C.column_id=1
ORDER BY TableName
2.查询当前表所有字段,数据,约束
复制代码 代码如下:
select
tabName=O.NAME,
columnLine=C.column_id,
columnName=C.name,
typeNum=T.name,
typeLength=C.max_length,
fState=ISNULL(G.value,N''),
isAbleNull=CASE WHEN C.is_nullable=1 THEN N'√'ELSE N'' END,
defaultData=ISNULL(D.definition,N''),
isIdentity=CASE WHEN C.is_identity=1 THEN N'√'ELSE N'' END,
isPrimary=case when exists(SELECT 1 FROM sysobjects where xtype='PK' and parent_obj=c.[object_id] and name in (
SELECT name FROM sysindexes WHERE indid in( SELECT indid FROM sysindexkeys WHERE id = c.[object_id] AND colid=c.column_id))) then '√' else '' end,
isForeign=case when exists(select * from sysforeignkeys fk where C.[object_id]=FK.fkeyid AND C.column_id=FK.fkey)then '√' else '' end,
TabForeignName=ISNULL(IDX.FKName,N''),
OutNameCol=ISNULL(IDX.ns,N'')
FROM sys.columns C
INNER JOIN sys.objects O
ON C.[object_id]=O.[object_id]
AND O.type='U'
AND O.is_ms_shipped=0
INNER JOIN sys.types T
ON C.user_type_id=T.user_type_id
left JOIN sys.extended_properties G
ON C.[object_id]=G.major_id and c.column_id=g.minor_id
LEFT JOIN sys.default_constraints D
ON C.[object_id]=D.parent_object_id
AND C.column_id=D.parent_column_id
AND C.default_object_id=D.[object_id]
left join sysforeignkeys fk
on C.[object_id]=FK.fkeyid
and C.column_id=FK.fkey
LEFT JOIN -- 索引及主键信息
(
SELECT
IDX.fkeyid,
IDX.fkey,
FKName=o.name,
ns=ss.name
FROM sysforeignkeys IDX
INNER JOIN sys.objects O
ON IDX.rkeyid=O.[object_id]
AND O.type='U'
AND O.is_ms_shipped=0
left join syscolumns ss
on IDX.rkeyid=ss.id
and IDX.RKEY=SS.COLID
)IDX
ON C.[object_id]=IDX.fkeyid
AND C.column_id=IDX.fkey
WHERE O.name=N'{0}' ------要查询的表名
ORDER BY O.name,C.column_id
3.字段
要加单引号varchar,char,nvarchar,nchar,text,ntext,datetime
不需要加int,numeric,bit 不需要加
带长度:[binary],[char],[decimal],[nchar],[numeric],[nvarchar],[varbinary][varchar]
不用带:[bigint],[bit],[datetime],[float],[image],[int],[xml],[timestamp],[tinyint],
[uniqueidentifier],[money],[ntext],[real],[smalldatetime],[smallint],[smallmoney],
[sql_variant],[text]
sql脚本,数据库
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。