SQL常用的操作

2021-09-28 22:27:47 字數 441 閱讀 2859

1、乙個表向另乙個表插入資料

insert into 表名1 (欄位1,欄位2,欄位3,…)

select 欄位1,欄位2,欄位3,…

from 表名2

where 過濾條件

注意:insert 的字段要select的字段型別和個數要相一致,並且還要注意通過檢視新增資料,不能使用關鍵字default

2、複製表的定義及資料

複製表資料:

create table 表名2 as select * from 表名1 ;

複製表定義

create table 表名2 as select * from 表名1 where 1=2;

注意:複製的表不包含約束、預設值、索引,要重新建立

3、增加表的字段

alter table 表名 add 欄位名 資料型別 default 『預設值』 ;

SQL常用的操作

1.dll 運算元據庫 表 列等 使用的關鍵字為 create alter drop 建立 create database mydb1 查詢 查詢當前資料庫伺服器中的所有資料庫 show databases 查詢前面建立mydb1資料庫的定義資訊 show create database mydb1...

sql常用操作

建立資料庫 create database nimeux test on name nimeux test,filename d nimeux test.mdf size 4,maxsize 10,filegrowth 1 刪除資料庫 use nimeux test create table dbo...

SQL 常用操作

今天網龍筆試遇到了幾個sql題,現在順便就總結一下常用的sql操作。內連線 只將符合條件的行顯示出來 select s.name,m.mark from student s,mark m where s.id m.studentid select s.name,m.mark from student...