Sql Server Éú³ÉÊý¾Ý×Öµä
use Dbname
go
select
[±íÃû]=c.Name,
[±í˵Ã÷]=isnull(f.[value],''),
[ÁÐÃû]=a.Name,
[ÁÐÐò號]=a.Column_id,
[±êʶ]=case when is_identity=1 then '√' else '' end,
[Ö÷鍵]=case when exists(select 1 from sys.objects x join sys.indexes y on x.Type=N'PK' and x.Name=y.Name
join sysindexkeys z on z.ID=a.Object_id and z.indid=y.index_id and z.Colid=a.Column_id)
then '√' else '' end,
[ÀàÐÍ]=b.Name,
[×Ö½ÚÊý]=case when a.[max_length]=-1 and b.Name!='xml' then 'max/2G'
when b.Name='xml' then '2^31-1×Ö節/2G'
else rtrim(a.[max_length]) end,
[³¤¶È]=case when ColumnProperty(a.object_id,a.Name,'Precision')=-1 then '2^31-1'
else rtrim(ColumnProperty(a.object_id,a.Name,'Precision')) end,
[СÊý]=isnull(ColumnProperty(a.object_id,a.Name,'Scale'),0),
[ÊÇ·ñΪ¿Õ]=case when a.is_nullable=1 then '√' else '' end,
[ÁÐ˵Ã÷]=isnull(e.[value],''),
[ĬÈÏÖµ]=isnull(d.text,'')
from
sys.columns a &
Ïà¹ØÎĵµ£º
¹Ì¶¨³¤¶È(char)Óë¿É±ä³¤¶È(varchar)×Ö·ûÊý¾ÝÀàÐÍ
char[(n)]
³¤¶ÈΪn¸ö×ֽڵĹ̶¨³¤¶ÈÇÒ·ÇUnicodeµÄ×Ö·ûÊý¾Ý¡£n±ØÐëÊÇÒ»¸ö½éÓÚ1ºÍ8,000Ö®¼äµÄÊýÖµ¡£´æ´¢´óСΪn¸ö×Ö½Ú¡£charÔÚSQL-92ÖеÄͬÒå´ÊΪcharacter¡£
varchar[(n)]
³¤¶ÈΪn¸ö×ֽڵĿɱ䳤¶ÈÇÒ·ÇUnicodeµÄ×Ö·ûÊý¾Ý¡£n±ØÐëÊÇÒ»¸ö½éÓÚ1ºÍ8,000Ö®¼äµÄÊýÖµ¡£´æ´¢´óСΪ ......
--Èç¹ûÊÇʵ±í¿ÉÒÔÓÃ
if exists (select * from sysobjects where id = object_id(N'[dbo].[±íÃû]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[±íÃû]
--Èç¹ûÊÇÁÙʱ±í¿ÉÒÔÓÃ(˵Ã÷,Èç¹ûÓòéÕÒʵ±í·½·¨À´´òÁÙʱ±í»áÕÒ²»µ½.·¢²¼Çø±ð¶Ô´ú.)
if object_id('tempdb..##temp') is not null
......
SQLº¯Êý
ÔÚSQLÖУ¬º¯Êý¶ÔÊý¾Ý»òÊý¾Ý×éÖ´ÐвÙ×÷£¬È»ºó·µ»ØÐèÒªµÄÖµ¡£º¯Êý±í´ïʽ¿ÉÒÔ³öÏÖÔÚSELECTÁбíÖУ¬»òÕß
ÔÚÈκÎÔÊÐí³öÏÖµÄλÖÃÉÏ¡£SQL°üº¬ÁËÆßÖÖº¯Êý:
(1)¾ÛºÏº¯Êý:·µ»Ø»ã×ÜÖµ¡£
(2)תÐͺ¯Êý:½«Ò»ÖÖÊý¾ÝÀàÐÍת»»ÎªÁíÍâÒ»ÖÖ¡£
(3)ÈÕÆÚº¯Êý:´¦ÀíÈÕÆÚºÍʱ¼ä¡£
(4)Êýѧº¯Êý:Ö´ÐÐËãÊõÔËËã¡£
(5)×Ö·û´®º¯Êý:¶Ô×Ö·û´ ......
ÄãÊÇ·ñÓöµ½¹ý ÏëÔÚ ×Ö·û´®ÀïÃæÐ´ SQLÓï¾ä£¬µ«ÊÇ×ÜÊÇÓöµ½ ijЩ·ûºÅ²»»áд.
±ÈÈç˵ÔÚ×Ö·û´®ÀïÃæÐ´¸ö±äÁ¿.
like: str sql="select * from abc where id= ' "++" ' "
idµÄ±äÁ¿Ó¦ ÏÈÓõ¥ÒýºÅÈ»ºó“+”ºÅ¡£
½ñÌìÓöµ½¸öºÜ³¤µÄSQLÓï¾ä£¬¶øÇÒSQLÓï¾äÀïÃæÇ¶Ì×ÁË×Ö·û´®¡£µ±Ê±¸ù±¾²»»áд ......