Êý¾Ý×ֵ䣨SQLÓï¾ä£©
declare @tmp table
(
id int identity(1,1),
TableName varchar(100),
Column_name varchar(100),
Type varchar(50),
Lenght int,
Scale int,
Nullable varchar(1),
Defaults varchar(4000),
PrimaryKey varchar(1)
)
select iid = identity(int,1,1), * into #a from SysObjects where xtype = 'U'
declare @i int
declare @max int
declare @table varchar(100)
set @i = 1
select @max = max(iid) from #a
while @i <= @max
begin
select @table = name from #a where iid = @i
if @@rowcount > 0
begin
insert @tmp (TableName, Column_name, Type, Lenght, Scale, Nullable, Defaults,PrimaryKey)
select @table, a.name, c.name, a.length, a.xscale, case a.isnullable when 0 then 'N' else 'Y' end, isnull(d.text,''), case when x.PrimaryKey is null then '' else x.PrimaryKey end
from SysColumns a with(nolock)
inner join (select * from SysObjects with(nolock) where xtype = 'U' and id = object_id(@table)) b on a.id = b.id
inner join SysTypes c with(nolock) on a.xtype = c.xusertype
left join syscomments d with(nolock) on a.cdefault = d.id
left join
(select f.id, colid, 'Y' as PrimaryKey from SysIndexKeys f with(nolock), SysIndexes e, SysObjects g
where f.id = e.id and f.indid = e.indid and f.id = g.parent_obj and e.name = g.name
and g.xtype = 'PK' and g. parent_obj = object_id(@table)) x on a.id = x.id and a.colid = x.colid
end
set @i = @i + 1
end
select * from @tmp
Ïà¹ØÎĵµ£º
[ÕªÒª] ȱʡÇé¿öϽ¨Á¢µÄË÷ÒýÊÇ·ÇȺ¼¯Ë÷Òý£¬µ«ÓÐʱËü²¢²»ÊÇ×î¼ÑµÄ¡£ÔÚ·ÇȺ¼¯Ë÷ÒýÏ£¬Êý¾ÝÔÚÎïÀíÉÏËæ»ú´æ·ÅÔÚÊý¾ÝÒ³ÉÏ¡£
ÓÅ»¯Êý¾Ý¿âµÄ×¢ÒâÊÂÏ
¡¡¡¡1¡¢¹Ø¼ü×ֶν¨Á¢Ë÷Òý¡£
¡¡¡¡2¡¢Ê¹Óô洢¹ý³Ì£¬ËüʹSQL±äµÃ¸ü¼ÓÁé»îºÍ¸ßЧ¡£
¡¡¡¡3¡¢±¸·ÝÊý¾Ý¿âºÍÇå³ýÀ¬»øÊý¾Ý¡£
¡¡¡¡4¡¢SQLÓï¾äÓï·¨µÄÓÅ»¯¡££¨¿ÉÒÔÓÃSybaseµÄSQL E ......
±¾ÎĽ«½éÉÜÀûÓÃSQL½¨Á¢Ë÷ÒýµÄ·½·¨¡£
¡¡¡¡¼ÙÉèÄãÏëÕÒÊéÖеÄijһ¸ö¾ä×Ó¡£Äã¿ÉÒÔÒ»Ò³Ò»Ò³µØÖðÒ³ËÑË÷£¬µ«Õâ»á»¨ºÜ¶àʱ¼ä¡£¶øÍ¨¹ýʹÓÃË÷Òý£¬Äã¿ÉÒÔºÜ¿ìµØÕÒµ½ÄãÒªËÑË÷µÄÖ÷Ìâ¡£
¡¡¡¡±íµÄË÷ÒýÓ븽ÔÚÒ»±¾ÊéºóÃæµÄË÷Òý·Ç³£ÏàËÆ¡£Ëü¿ÉÒÔ¼«´óµØÌá¸ß²éѯµÄËÙ¶È¡£¶ÔÒ»¸ö½Ï´óµÄ±íÀ´Ëµ£¬Í¨¹ý¼ÓË÷Òý£¬Ò»¸öͨ³£Òª»¨·Ñ¼¸¸öСʱÀ´Íê³ÉµÄ²éÑ¯Ö ......
---------Êýѧº¯Êý ---------------
¡¡¡¡1.¾ø¶ÔÖµ
¡¡¡¡S:select abs(-1) value
¡¡¡¡O:select abs(-1) value from dual
¡¡¡¡2.È¡Õû(´ó)
¡¡¡¡S:select ceiling(-1.001) value
¡¡¡¡O:select ceil(-1.001) value from dual
¡¡¡¡3.È¡Õû£¨Ð¡£©
¡¡¡¡S:select floor(-1.001) value
¡¡¡¡O:select floor(-1.001) value from ......
¡¡¡¡Ëæ»ú¶ÁÈ¡Èô¸ÉÌõ¼Ç¼£¬²âÊÔ¹ý
AccessÓï·¨£ºSELECT top 10 * from ±íÃû ORDER BY Rnd(id)
Sql server:select top n * from ±íÃû order by newid()
mysql select * from ±íÃû Order By rand() Limit n
¡¡¡¡ËµÃ÷£ºÑ¡Ôñ´Ó10µ½15µÄ¼Ç¼
select top 5 * from (select top 15 * from table order by id asc) table_±ðÃû or ......