好长时间没有用SQL了...还停留在学生时代的水平... 转: 昨天遇到个面试题:查询一个表里面某个字段值相同的数据记录,好久没有写过这种,还真的花了点时间才写出来.如表g_carddetail,有 g_no g_name g_id g_state 这个字段,现在要求查询出存在g_id相同大于等于2的数据记录:select * from g_carddetail a where exists(select g_id from g_carddetail where g_id = a.g_id gr
查询数据库里所有表名和字段名的语句SQL 查询所有表名:SELECT NAME FROM SYSOBJECTS WHERE TYPE='U'SELECT * FROM INFORMATION_SCHEMA.TABLES查询表的所有字段名:SELECT NAME FROM SYSCOLUMNS WHERE ID=OBJECT_ID(' 表名' )SELECT * FROM INFORMATION_SCHEMA.TABLESSELECT * FROM INFORMATION_SCHEMA.VIEWS
写作业的时候发现书上竟然找不到查询约束的语句,百度搜了好久的资料,终于查询成功,在这里记录下来 主键约束 SELECT tab.name AS [表名], idx.name AS [主键名称], col.name AS [主键列名] FROM sys.indexes idx JOIN sys.index_columns idxCol ON (idx.object_id = idxCol.object_id AND idx.index_id
SELECT t.name AS table_name, c.name AS column_name FROM XOIFundData.sys.tables AS t INNER JOIN XOIFundData.sys.columns c ON t.OBJECT_ID = c.OBJECT_ID WHERE c.name LIKE '%RoleInPortfolio%'
ms sql server 1.查询所有表select [id], [name] from [sysobjects] where [type] = 'u' order by [name]2.查询所有数据库3.select [name] from [sysdatabases] order by [name]查询表中字段 select [name] from [syscolumns] where [name] = 'tableXXX'order by [colid] oracle 1.查找表的所有索
1.获取所有用户名SELECT name FROM Sysusers where status='2' and islogin='1'islogin='1'表示帐户islogin='0'表示角色status='2'表示用户帐户status='0'表示糸统帐户 2.获取所有数据库名SELECT Name FROM Master..SysDatabases ORDER BY Name 3.获取所有表名SELECT Name FROM DatabaseName..SysObjects Where XT
A.B两表,找出ID字段中,存在A表,但是不存在B表的数据. 方法一:使用 not inselect distinct A.ID from A where A.ID not in (select ID from B) 方法二:使用 left join...on... , "B.ID isnull" 表示左连接之后在B.ID 字段为 null的记录select A.ID from A left join B on A.ID=B.ID where B.ID is null 方法三:sele
网上查了很多资料,最后发现一个可行的,分享如下: 数据库大小查询: select concat(round(sum(DATA_LENGTH/1024/1024),2),'M') from information_schema.TABLES where TABLE_SCHEMA='数据库名称'; 表大小查询:SELECT concat(round(sum(DATA_LENGTH/1024/1024),2),'M') FROM information_schema.TABLES where TABL
select * from zyz_mgr_wlcyiduifu a left join WLCInformation b ona.wlcId=b.WLCInvestorApplyID where b.WLCInvestorApplyID is null //如果左表数据带 单引号 及逗号 select * from zyz_mgr_wlcyiduifu a left join WLCInformation b on replace(replace(a.wlcId,'''',''),',',''
一般我们用SELECT .... INTO语句生成的表字段都是允许为NULL.而如果我们需要改成NOT NULL呢 select 'ALTER TABLE dbo.XXXXXXX ALTER COLUMN ' + QUOTENAME(c.name) + ' ' + t.name + case when t.name in ('nvarchar','nchar') as nvarchar) +')' when t.name in ('varchar','binary', 'char', 'varb
1.基础环境 创建基础表: CREATE TABLE TEST_TAB1( ID INT, NAME VARCHAR2(20) ); CREATE TABLE TEST_TAB2( ID INT, NAME VARCHAR2(20) ); CREATE TABLE TEST_TAB3( ID INT, NAME VARCHAR2(20) ); CREATE TABLE TEST_IN_TAB( ID INT, NAME VARCHAR2(20) ); 插入基础数据: INSERT INTO TE