用SQL語句建立表修改表

2021-08-25 17:41:09 字數 1678 閱讀 9975

1. 建立表

create table 學生資訊

(學號varchar(14) identity(1,1) primary key,

姓名varchar(8) unique not null,

班級編號varchar(14) references '班級資訊',

年級int null,

性別varchar(2) check(性別in ('男』','女』)),

民族varchar(20) default '未知該生民族',

籍貫varchar(50)

)2. 修改表

1)重新命名表:

exec sp_rename 『oldname』,』newname』

2)修改列屬性:

alter table 學生資訊

alter column 姓名varchar(20) not null

3)新增列:

alter table 學生資訊

add 家庭住址nvarchar(20) null

4)刪除列:

alter table 學生資訊

drop column 家庭住址cascade

附sql語句集錦

--語 句 功 能

--資料操作

select --從資料庫表中檢索資料行和列

insert --向資料庫表新增新資料行

delete --從資料庫表中刪除資料行

update --更新資料庫表中的資料

--資料定義

create table --建立乙個資料庫表

drop table --從資料庫中刪除表

alter table --修改資料庫表結構

create view --建立乙個檢視

drop view --從資料庫中刪除檢視

create index --為資料庫表建立乙個索引

drop index --從資料庫中刪除索引

create procedure --建立乙個儲存過程

drop procedure --從資料庫中刪除儲存過程

create trigger --建立乙個觸發器

drop trigger --從資料庫中刪除觸發器

create schema --向資料庫新增乙個新模式

drop schema --從資料庫中刪除乙個模式

create domain --建立乙個資料值域

alter domain --改變域定義

drop domain --從資料庫中刪除乙個域

--資料控制

grant --授予使用者訪問許可權

deny --拒絕使用者訪問

revoke --解除使用者訪問許可權

--事務控制

commit --結束當前事務

rollback --中止當前事務

set transaction --定義當前事務資料訪問特徵

--程式化sql

declare --為查詢設定游標

explan --為查詢描述資料訪問計畫

open --檢索查詢結果開啟乙個游標

fetch --檢索一行查詢結果

close --關閉游標

prepare --為動態執行準備sql 語句

execute --動態地執行sql 語句

describe --描述準備好的查詢

用SQL語句修改SQL表結構

用sql語句修改sql表結構 解決方法 在選單中找到 工具 在 工具 的下拉列表中找到 選項 開啟 選項 你會看到 designers 中有一條 阻止儲存要求重新建立表的修改 去掉前面的勾勾。注意,這樣用的時候,一定要注意表的關聯。另外,可以用sql語句來更改,以下為相應的 例項 1.更改字段型別長...

SQL語句修改表

更改字段型別 預設值 alter table 表名 alter column 欄位名 型別 alter table 表名 add default 修改後的預設值 for 欄位名 with values 注 如果該欄位以前已經有預設值了,在修改之前需要先將約束刪除,否則會報錯 刪約束的 alter t...

sql語句建立表

create table search custom mall id int 11 not null primary keyauto increment,uid int 11 not null name varchar 150 not null search mall id int 11 not n...