mysql 定義語言

2021-09-05 09:56:04 字數 1011 閱讀 2104

– ddl 資料庫定義語言

– sql語句

– 關係模型資料庫由表組成 表室友實體和聯絡組成

create database demo178

– 使用資料庫

use demo178

– 刪除資料庫

drop database demo178

– 建立表

– create table 表名 (

– 列名 列名的資料型別 primary key(主鍵),

– 列名 列名的資料型別,如果是varchar型別 需要定義該列的大小 not null不能為空的約束

– )– references t_class(c_id) 這一句僅僅是給學生表加了乙個外來鍵 並沒有加約束

– 分清什麼事外來鍵 什麼是外來鍵約束

– 當建立表的時候 這個表有外來鍵約束 那麼需要先建立主表 然後在建立從表

– 外來鍵保證我們引用完整性

create table t_student(

s_id int primary key auto_increment,

s_name varchar(10) not null,

s_*** varchar(2) default 『男』,

s_date date,

s_phone int unique,

s_cid int ,

constraint foreign key(s_cid) references t_class(c_id)

)– 新增外來鍵約束

– s_cid int references t_class(c_id)

– 建立班級表 班級表示主表t_class

create table t_class(

c_id int primary key,

c_name varchar(20)

)– 刪除表 刪除表時注意 當有外來鍵約束的時候 先刪除從表 然後刪除主表

drop table t_student

drop table t_class

My SQL資料定義語言 DDL

create if notexists db name create specification create specification create specification default character set charset name default collate collatio...

MySQL 資料定義語言(DDL)

mysql 資料定義語言 ddl 一 create命令 1 建立資料庫 create database if not exists 資料庫名 例 create database aa 2 建立資料表 create table if not exists 表名 欄位名1 列型別 屬性 索引 注釋 欄位...

MySQL基礎 資料定義語言

資料定義語言 一 庫的管理 建立 修改 刪除 二 表的管理 建立 修改 刪除 建立 create 修改 alter 刪除 drop 一 庫的管理 1 庫的建立 語法 create database if not exist 庫名 create database if not exist books ...