SQL語句建表等

2021-08-23 15:02:27 字數 783 閱讀 6716

以下就是示例:

用 ddl 的 create table 建立乙個表 table1 ,主鍵是自動編號字段,另乙個欄位是長度是 10 的文字字段。

create table table1 (id counter constraint primarykey primary key, mytext text (10))

再建乙個包含兩個欄位的表 table2,字段 id 為長整型,字段 mytext 為文字

create table table2 (id long, mytext text)

用以下語句建立 table1 和 table2 的一對多關係:

alter table table2 add constraint relation1 foreign key ([id]) references table1 ([id])

刪除關係用以下語句:

alter table table2 drop constraint relation1

刪除 table1 用以下語句:

drop table table1

設定某欄位為主鍵

alter table 表1 alter column [id] counter constraint myprimarykey primary key

增加乙個字段 mysalary

alter table aaa add column mysalary currency

刪除乙個字段 mysalary

alter table aaa drop column mysalary

sql中建庫建表的sql語句

建庫 use master goif exists select from sysdatabases where name news drop database news gocreate database news on primary name news filename f dbproject...

用SQL語句建表,建庫,建約束

sql資料庫 建立資料庫 判斷 if exists select from sysdatabases where name 資料庫名 drop database 資料庫名 gocreate database 資料庫名on name 資料庫名 filename d 名.mdf 路徑 size 3,初始...

Oracle建表,修改字段,建序列等語句

建表 create table tb user id intnot null username varchar 32 not null password varchar 32 not null phone varchar 32 not null,primary key id 建立序列 create ...