»ª·áÈí¼þ

»¥ÁªÍøÈí¼þ×ÊÔ´¹²Ïí

µ±Ç°Î»ÖãºÊ×Ò³ -> ×ÛºÏƵµÀ -> Õ¾³¤Ö®¼Ò

´´½¨±í Ìí¼ÓÖ÷¼ü Ìí¼ÓÁг£ÓÃSQLÓï¾ä

--ɾ³ýÖ÷¼ü

alter table ±íÃû drop constraint Ö÷¼üÃû
--Ìí¼ÓÖ÷¼ü
alter table ±íÃû add constraint Ö÷¼üÃû primary key(×Ö¶ÎÃû1,×Ö¶ÎÃû2¡­¡­)
--Ìí¼Ó·Ç¾Û¼¯Ë÷ÒýµÄÖ÷¼ü
alter table ±íÃû add constraint Ö÷¼üÃû primary key NONCLUSTERED(×Ö¶ÎÃû1,×Ö¶ÎÃû2¡­¡­)

н¨±í£º
create table [±íÃû]
(
[×Ô¶¯±àºÅ×Ö¶Î] int IDENTITY (1,1) PRIMARY KEY ,
[×Ö¶Î1] nVarChar(50) default \'ĬÈÏÖµ\' null ,
[×Ö¶Î2] ntext null ,
[×Ö¶Î3] datetime,
[×Ö¶Î4] money null ,
[×Ö¶Î5] int default 0,
[×Ö¶Î6] Decimal (12,4) default 0,
[×Ö¶Î7] image null ,
)

ɾ³ý±í£º
Drop table [±íÃû]

ɾ³ýËùÓÐ±í£º

DECLARE curItems CURSOR
FOR select [name] from sysobjects where xtype='U'
FOR READ ONLY
OPEN curItems
DECLARE @n  NVARCHAR(100),@m NVARCHAR(100)
FETCH FROM curItems INTO @n
WHILE @@FETCH_STATUS=0
BEGIN
set @m=@n
   exec('Drop Table ' + @m)
FETCH NEXT FROM curItems INTO
@n
END
CLOSE  curItems
DEALLOCATE  curItems

²åÈëÊý¾Ý£º
INSERT INTO [±íÃû] (×Ö¶Î1,×Ö¶Î2) VALUES (100,\'51WINDOWS.NET\')

ɾ³ýÊý¾Ý£º
DELETE FROM [±íÃû] WHERE [×Ö¶ÎÃû]>100

¸üÐÂÊý¾Ý£º
UPDATE [±íÃû] SET [×Ö¶Î1] = 200,[×Ö¶Î2] = \'51WINDOWS.NET\' WHERE [×Ö¶ÎÈý] = \'HAIWA\'

ÐÂÔö×ֶΣº
ALTER TABLE [±íÃû] ADD [×Ö¶ÎÃû] NVARCHAR (50) NULL

ɾ³ý×ֶΣº
ALTER TABLE [±íÃû] DROP COLUMN [×Ö¶ÎÃû]

ÐÞ¸Ä×ֶΣº
ALTER TABLE [±íÃû] ALTER COLUMN [×Ö¶ÎÃû] NVARCHAR (50) NULL

ÖØÃüÃû±í£º(Access ÖØÃüÃû±í£¬Çë²Î¿¼ÎÄÕ£ºÔÚAccessÊý¾Ý¿âÖÐÖØÃüÃû±í)
sp_rename \'±íÃû\', \'бíÃû\', \'OBJECT\'

н¨Ô¼Êø£º
ALTER TABLE [±íÃû] ADD CONSTRAINT Ô¼ÊøÃû CHECK ([Ô¼Êø×Ö¶Î] <= \'2000-1-1\')

ɾ³ýÔ¼Êø£º
ALTER TABLE [±íÃû] DROP CONSTRAINT Ô¼ÊøÃû

н¨Ä¬ÈÏÖµ
ALTER TABLE [±íÃû] ADD CONSTRAINT ĬÈÏÖµÃû DEFAULT \'51WINDOWS.NET\' FOR [×Ö¶ÎÃû]

ɾ³ýĬÈÏÖµ
ALTER TABLE [±íÃû] DROP CONSTRAINT ĬÈÏÖµÃû

ɾ³ýSql Server ÖеÄÈÕÖ¾£¬¼õСÊý¾Ý¿âÎļþ´óС
dump transaction Êý¾Ý¿âÃû with no_log
backup log Êý¾Ý¿âÃû with no_log
dbcc shrinkdatabase(Êý¾Ý¿âÃû)
exec sp_dboption \'Êý¾Ý¿âÃû\', \'autoshrink\', \'true\'

\\\'Ìí¼Ó×Ö¶ÎͨÓú¯Êý
Sub AddColumn(TableName,ColumnName,ColumnType)
Conn.Execute(\"Alter Table \"&TableName&\" Add \"&ColumnName&\" \"&ColumnType&\"\")
End Sub

\\\'¸ü¸Ä×Ö¶ÎͨÓú¯Êý
Sub ModColumn(TableName,ColumnName,ColumnType)
Conn.Execute(\"Alter Table \"&TableName&\" Alter Column \"&ColumnName&\" \"&ColumnType&\"\")
End Sub

\\\'¼ì²é±íÊÇ·ñ´æÔÚ

sql=\"select count(*) as dida from sysobjects where id = object_id(N\'[ËùÓÐÕß].[±íÃû]\') and OBJECTPROPERTY(id, N\'IsUserTable\') = 1\"

set rs=conn.execute(sql)

response.write rs(\"dida\")\'·µ»ØÒ»¸öÊýÖµ£¬0´ú±íûÓУ¬1´ú±í´æÔÚ


ÅжϱíµÄ´æÔÚ:
select * from sysobjects where id = object_id(N\'[dbo].[tablename]\') and OBJECTPROPERTY(id, N\'IsUserTable\') = 1

ij¸ö±íµÄ½á¹¹
select * from syscolumns where id = object_id(N\'[dbo].[ÄãµÄ±íÃû]\') and OBJECTPROPERTY(id, N\'IsUserTable\') = 1

Ð޸ıíµÄǰ׺:

ALTER SCHEMA dbo TRANSFER prename.tablename;

Èç¹û±í2ÒѾ­´æÔÚ£¬°Ñ±í1ÖеļǼ¼Óµ½±í2ÖеÄÓï¾ä£º
insert   into   ±í2   (×Ö¶Î1,×Ö¶Î2,...)   select   ×Ö¶Î1,×Ö¶Î2,..   from   ±í2   where   ...

Èç¹û±í2²»´æÔÚ£¬ÔòÓÃÏÂÃæµÄÓï¾ä»á×Ô¶¯Éú³É±í2£¬×ֶεÄÀàÐͺͱí1Ò»Ñù£º
       select   ×Ö¶Î1,×Ö¶Î2,..   INTO   ±í2   from   ±í1   where   ...



ÉÏһƪ£ºB6.0²Ù×÷SQL Server¡ª¡ªÔöɾ¸Ä²é
ÏÂһƪ£ºSQlÌí¼Ó¡¢É¾³ý¡¢ÐÞ¸ÄÓï¾ä VB ADO ..

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

ËÑË÷
×îÐÂÎÄÕÂ
ͼƬÖ÷Ìâ
ÈÈÃÅÎÄÕÂ
ÍƼöÎÄÕÂ
Ïà¹ØÎÄÕÂ

    Ê× Ò³   |   °æȨÉùÃ÷   |   ¹ØÓÚÎÒÃÇ   |   ¹ã¸æ·þÎñ   |   ÁªÏµÎÒÃÇ   |   ÊÖ»ú°æ    |   ÍøÕ¾µØͼ
    Copyright@zhuchunyu.com all rights reserved
    Powered by zhuchunyu.com 2018-2025 zhuchunyu.com ÍîICP±¸05011767ºÅ-23