午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    Sql Server 添加刪除字段判斷表或字段是否存在得到
    來(lái)源:易賢網(wǎng) 閱讀:2334 次 日期:2014-11-03 11:49:09
    溫馨提示:易賢網(wǎng)小編為您整理了“Sql Server 添加刪除字段判斷表或字段是否存在得到”,方便廣大網(wǎng)友查閱!

    增加字段

    alter table docdsp add dspcode char(200)

    刪除字段

    ALTER TABLE table_NAME DROP COLUMN column_NAME

    修改字段類型

    ALTER TABLE table_name ALTER COLUMN column_name new_data_type

    改名

    sp_rename

    更改當(dāng)前數(shù)據(jù)庫(kù)中用戶創(chuàng)建對(duì)象(如表、列或用戶定義數(shù)據(jù)類型)的名稱。

    語(yǔ)法

    sp_rename [ @objname = ] 'object_name' ,

    [ @newname = ] 'new_name'

    [ , [ @objtype = ] 'object_type' ]

    =======================================================

    --假設(shè)要處理的表名為: tb

    --判斷要添加列的表中是否有主鍵

    if exists(select 1 from sysobjects where parent_obj=object_id('tb') and xtype='PK')

    begin

    print '表中已經(jīng)有主鍵,列只能做為普通列添加'

    --添加int類型的列,默認(rèn)值為0

    alter table tb add 列名 int default 0

    end

    else

    begin

    print '表中無(wú)主鍵,添加主鍵列'

    --添加int類型的列,默認(rèn)值為0

    alter table tb add 列名 int primary key default 0

    end

    /**************************************************************************************/

    判斷table1中是否存在name字段

    if exists(select * from syscolumns where id=object_id('table1') and name='name') begin

    select * from people;

    end

    ========================================================================

    如果是實(shí)表可以用

    if exists (select * from sysobjects where id = object_id(N'[dbo].[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[表名]--如果表存在就刪除

    如果是臨時(shí)表可以用

    if object_id('tempdb..##temp') is not null

    drop table ##temp

    說(shuō)明,如果用查找實(shí)表方法來(lái)打臨時(shí)表會(huì)找不到.發(fā)布區(qū)別對(duì)代.

    ==========================================================

    得到表字段的描述

    我一般用這個(gè)視圖

    Create view fielddesc

    as

    select o.name as oname, c.name as cname,convert(varchar(30),p.value) as value,p.smallid as psmallid,t.name as tname

    from syscolumns c

    join systypes t on c.xtype = t.xtype

    join sysobjects o on o.id=c.id

    left join sysproperties p on p.smallid=c.colid and p.id=o.id

    where o.xtype='U'

    查詢時(shí):

    Select * from fielddesc where oname = '你的表名'

    注:更多精彩教程請(qǐng)關(guān)注三聯(lián)教程 頻道,

    更多信息請(qǐng)查看IT技術(shù)專欄

    更多信息請(qǐng)查看數(shù)據(jù)庫(kù)
    易賢網(wǎng)手機(jī)網(wǎng)站地址:Sql Server 添加刪除字段判斷表或字段是否存在得到
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2025國(guó)考·省考課程試聽(tīng)報(bào)名

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)