Sql基礎語句

2021-09-25 03:40:42 字數 1162 閱讀 7558

--這是sql語句的注釋

--1:建立資料庫

create database mytest001

--2:刪除資料庫

--drop database mytest001

--3:建立資料表

--drop table mytesttable001

--使用use [資料庫名],執行後那麼後續的操作都是在該資料庫下進行的

use mytest001

create table mytesttable001

(id int,

name nvarchar(10),

)drop table mytesttable001

--建立表時指定主鍵並且通過標誌規範設定主鍵的種子及增量(要是int型才可以)

create table mytesttable002

(id int primary key identity(1,1),--id為主鍵,第乙個為1,增量為1,即1,2,3,4,5....

name nvarchar(10),

age int,

)--增

--向資料表中新增相應的資料

insert mytesttable002 values('lanbo',20)--注意格式,由於id系統會根據標識主動填入,不能自己寫值

insert mytesttable002 values('jack',22)

--查select * from mytesttable002--查詢表中全部內容

select * from mytesttable002 where age>20--條件查詢

select * from mytesttable002,demo1_student.dbo.student where mytesttable002.id=demo1_student.dbo.student.id

--改update mytesttable002 set name='lanbo1' where id='2'--將主鍵為2的一項的name設定為lanbo1

--update mytesttable002 set name='lanbo1'--不選擇的話就是將所有行的name設定為lanbo1

--刪delete mytesttable002 where name='lanbo1'

SQL基礎語句

一.資料庫查詢語句 select 1.查詢所有資料 select from 表名 select from exam books 2.按照一定的條件查詢 select from 表名 where 條件 select from exam books where id 20 3.範圍條件查詢 select...

SQL基礎語句

1.1.1dml 資料操作語言 1.1.2 ddl 資料定義語言 select update delete insert 1.2.1 select語法a.查詢所有 select from 表名 b.查詢列 select 列名 from 表名 注意 查詢列名時,列名用逗號隔開,最後的列名不要加逗號1....

基礎sql語句

從資料庫中刪除資料 delete 插入資料 insert into 建立新資料庫 create database 修改資料庫 alter database 建立新錶 create table 變更資料庫表 alter table 刪除表 drop table 建立索引 create index 刪除...