Sql Server 基礎語法

2021-08-19 01:28:50 字數 631 閱讀 6681

1.新增乙個非空型別的字段,需要加預設值,否則會報錯

alter table [demo1].[dbo].[cities] add   testtime datetime  not null default getdate()
getdate() 獲取當前時間

2. 修改列名

if exists(select * from syscolumns where id=object_id('資料表名稱') and name='欄位名') --判斷該欄位是否存在

begin

alter table 表明 alter column 欄位名 varchar(64);--更改型別

endgo

if exists(select * from syscolumns where id=object_id('表名') and name='舊欄位名') --判斷該欄位是否存在

beginexec sp_rename '表明。舊欄位名', '新欄位名', 'column'; --更改欄位名稱 sp_rename 為資料儲存過程

endgo

SQL Server 臨時表插入基礎語法

有關臨時表的資料插入 1 把臨時表中的資料插入到另乙個表中 insert into 表 select from temp 2 把乙個表中字段複製到臨時表中 select into temp from 表 where 3 本地臨時表的名稱以單個數字符號 打頭 它們僅對當前的使用者連線是可見的 4 當使...

SQL Server基礎語法 增刪改查

1.插入單行資料insert into 表名 列名 values 值列表 當列名列有預設值時,輸入 default 2.插入多行資料 將現有資料庫值插入到新資料庫中 方法1 insert into 表名 列名 必須預先建立新的資料庫 select 列名 from 源表名 方法2 select 列名 ...

Sqlserver 語法總結

修改列型別 alter table pro element b alter column matname varchar 1024 更改乙個表中的資料到另外乙個表中 update a set a.name b.name from a,b where a.id b.id select into fro...