建立資料庫和表

2021-12-30 08:48:12 字數 934 閱讀 6922

sql server資料庫的型別

兩種資料庫:系統資料庫;使用者資料庫

sql server資料庫包含資料和日誌資訊;

主資料檔案:構造資料庫的主檔案,該檔案的副檔名必須為.mdf,sql server資料庫只能有乙個主資料檔案。

日誌資料檔案:儲存了萬一失敗時用於恢復資料庫的所有日誌資訊。該檔案的副檔名必須為.ldf。

建立資料庫:

create database database-name;

sql server資料庫型別

建立表:

create table mysqltable

name varchar(10) not null,--name value is a must and can't be null age int,

ssn varchar(11),

date datetime,

gender char(6)

alter table語句

alter table mysqltable

add id int identity(1,1)

刪除表drop table mysqltable

插入資料

insert into

,.......)

values(,,.....)

查詢:select *from mysqltable

更新資料:

update

set =,=,.....

where

刪除資料:

delete from

where

建立資料庫和表

一 建立資料庫 我們知道表是屬於架構的,而架構又是屬於資料庫的。要在sql server環境中建立乙個名為testdb的資料庫,可以執行以下 if db id testdb is null create database testdb 如果不存在名為testdb的資料庫,這段 就會建立乙個新的。db...

建立資料庫和表

一 建立資料庫 我們知道表是屬於架構的,而架構又是屬於資料庫的。要在sql server環境中建立乙個名為testdb的資料庫,可以執行以下 if db id testdb is null create database testdb 如果不存在名為testdb的資料庫,這段 就會建立乙個新的。db...

2 建立資料庫和表

我們將用到三張表 user,blog和post。我們使用的資料庫為test.你可以下面的表結構,也可以讓acriverecord 生成結構 正如你所見到的,user表和其他標沒有任何關聯。它只是用來控制對應用程式的訪問。同時blog表和post表示關聯的。乙個blog可以後多個post,因此關聯就是...