編輯:關於Android編程
廢話不多說了,具體詳情如下所示:
1.修改表名
格式:sp_rename tablename,newtablename
sp_rename tablename,newtablename
2.修改字段名
格式:sp_rename 'tablename.colname',newcolname,'column'
sp_rename 'tablename.colname',newcolname,'column'
3.添加字段
格式:alter table table_name add new_column data_type [interality_codition]
示例1
ALTER TABLE student Add nationality varchar(20)
--示例2 添加int類型的列,默認值為 0
alter table student add studentName int default 0 --示例3 添加int類型的列,默認值為0,主鍵 alter table student add studentId int primary key default 0 --示例4 判斷student中是否存在name字段且刪除字段 if exists(select * from syscolumns where id=object_id('student') and name='name') begin alter table student DROP COLUMN name end
4.更改字段
格式:alter table table_name alter column column_name
ALTER TABLE student ALTER COLUMN name VARCHAR(200)
5.刪除字段
格式:alter table table_name drop column column_name
ALTER TABLE student DROP COLUMN nationality;
6.查看字段約束
格式: select * from information_schema.constraint_column_usage where TABLE_NAME = table_name
SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME FROM information_schema.CONSTRAINT_COLUMN_USAGE WHERE TABLE_NAME = 'student'
7.查看字段缺省約束表達式 (即默認值等)
格式:select * from information_schema.columns where TABLE_NAME = table_name
SELECT TABLE_NAME, COLUMN_NAME, COLUMN_DEFAULT FROM information_schema.COLUMNS WHERE TABLE_NAME='student'
8.查看字段缺省約束名
格式:select name from sysobjects where object_id(table_name)=parent_obj and xtype='D'
select name from sysobjects where object_id('表?名?')=parent_obj and xtype='D'
9.刪除字段約束
格式:alter table tablename drop constraint constraintname
ALTER TABLE student DROP CONSTRAINT PK__student__2F36BC5B772B9A0B
10.添加字段約束
格式:alter table tablename add constraint constraintname primary key (column_name)
--示例1
ALTER TABLE stuInfo ADD CONSTRAINT PK_stuNo PRIMARY KEY (stuNo) --示例2 添加主鍵約束(Primary Key) -- 存在主鍵約束PK_stuNO,則刪除 IF EXISTS(SELECT * FROM sysobjects WHERE name='PK_stuNo' and xtype='PK') Alter TABLE stuInfo Drop Constraint PK_stuNo Go -- 重新添加主鍵約束PK_stuNO ALTER TABLE stuInfo ADD CONSTRAINT PK_stuNo PRIMARY KEY (stuNo) Go --示例3 添加 唯一UQ約束(Unique Constraint) -- 存在唯一約束UQ_stuNO,則刪除 IF EXISTS(SELECT * FROM sysobjects WHERE name='UQ_stuID' and xtype='UQ') Alter TABLE stuInfo Drop Constraint UQ_stuID Go -- 重新添加唯一約束UQ_stuID ALTER TABLE stuInfo ADD CONSTRAINT UQ_stuID UNIQUE (stuID) --示例4 添加默認DF約束(Default Constraint) -- 存在默認約束UQ_stuNO,則刪除 IF EXISTS(SELECT * FROM sysobjects WHERE name='DF_stuAddress' and xtype='D') Alter TABLE stuInfo Drop Constraint DF_stuAddress Go -- 重新添加默認約束DF_stuAddress ALTER TABLE stuInfo ADD CONSTRAINT DF_stuAddress DEFAULT ('地址不詳') FOR stuAddress --示例5 檢查CK約束(Check Constraint) -- 存在檢查約束UQ_stuNO,則刪除 IF EXISTS(SELECT * FROM sysobjects WHERE name='CK_stuAge' and xtype='C') Alter TABLE stuInfo Drop Cons
以上所述是小編給大家介紹的SQLSERVER實現更改表名,更改列名,更改約束代碼,希望對大家有所幫助!
微信公眾號是微信公眾平台下的一個小分支,有信息推廣推送的功能,公眾號每天定時的推送相關文章或者相關活動內容,讓用戶及時了解最新動態!那麼微信公眾號怎麼申請?
實現功能:實現NetMusicListAdapter(網絡音樂列表適配器)實現SearchResult(搜索音樂對象)使用Jsoup組件請求網絡,並解析音樂數據,並,音樂
前言:前面一篇分析了mediaplayerservice及MediaPlayer中的CS模型,但是對於如何能把數據解析出來,渲染到最終的SurfaceView上顯示,並且
了解了基本的自定義view基礎後,現在我們就來實踐下自定義view,也是看到我華為手機上自帶的天氣預報軟件後,想著模仿做一個,於是,我自己嘗試了下,雖然不算太像,但是還算