當前位置:首頁 » 編程語言 » sql新建表並錄入舊表的信息
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql新建表並錄入舊表的信息

發布時間: 2022-06-05 12:03:49

sql建表後如何寫入數據

1、手動插入,滑鼠右鍵點擊表名-->編輯前200行,然後手動填寫

2、使用SQL語句 insert into 表名 values(欄位數據,有多少個欄位就填對應的數據);
比如有 A 表中有id,name,age ,name是varchar類型的 添加語句就是
insert into a values(1,'ztm',20) 順便說一下我是菜鳥,大家不要噴

㈡ 在資料庫中創建數據表時,根據舊表創建新表的Sql怎麼寫

樓主真懶,
這些東西網路一下都有的:
execute
sp_configure'show
advanced
options',1
reconfigure
execute
sp_configure
'xp_cmdshell',1
reconfigure
execute
xp_cmdshell
'mkdir
e:\aaa'
execute
sp_configure
'xp_cmdshell',0
reconfigure
execute
sp_configure
'show
advanced
options',0
reconfigure
--
創建資料庫
impression
create
database
impression
on
primary
(
name
=
'impression',
filename
=
'e:\aaa\impression.mdf',
size
=
5,
maxsize
=
unlimited,
filegrowth
=
5
)
log
on
(
name
=
'impression_log',
filename
=
'e:\aaa\impression_log.ldf',
size
=
1,
maxsize
=
unlimited,
filegrowth
=
10%
)
go
--
創建
teacher

create
table
teacher
(
id
int
identity(1,1),
name
nvarchar(30),
sex
bit,
birthday
date,
telephone
nvarchar(15),
address
nvarchar(100),
email
nvarchar(100)
)
go
--
給表teacher添加,郵編
字元類型,長度6一列
alter
table
teacher
add
zipcode
nvarchar(6)
go
--
給表teacher
,欄位id添加主鍵
alter
table
teacher
add
constraint
pk_id
primary
key
(id)
go
--
創建索引i_teacher,優化欄位email和address
create
index
i_teacher
on
teacher
(email,address)
go
--
創建v_teacher視圖
???
這個問題沒有規定視圖中有什麼列啊?
create
view
v_teacher
as
(
select
*
from
teacher
)
go
--
刪除id欄位主鍵
alter
table
teacher
drop
constraint
pk_id
--
刪除索引i_teacher
drop
index
i_teacher
on
teacher
--
刪除視圖v_teacher
drop
view
v_teacher
--
刪除表teacher
drop
table
teacher
--
刪除資料庫impression
drop
database
impression

㈢ 如何通過SQL語句從資料庫讀取數據,在把讀到的數據寫入另一個新建表中去

復製表結構及數據到新表
CREATE TABLE 新表 SELECT * FROM 舊表

insert into 新表 (select * from 舊表)
前提是表結構相同

㈣ 求解SQL建表,以及如何錄入數據

sql server建立數據表

  • 1

    打開sql server,連接到伺服器;在「資料庫」文件夾上單擊滑鼠右鍵,選擇「新建資料庫」,彈出新建資料庫窗體;

㈤ 如何在已經建立好的SQL數據表中添加數據

1、雙擊打開MySQL軟體,在左側中找到【表】並且右擊選擇【新建表】

㈥ SQL語句 怎麼把從一個表中查出來數據插入到另一個表中

sql語句從一張表中查詢數據插入到另一張表中的方法如下:

1、select * into destTbl from srcTbl。

2、insert into destTbl(fld1, fld2) select fld1, 5 from srcTbl。

以上兩句都是將 srcTbl 的數據插入到 destTbl,但兩句又有區別的:

第一句(select into from)要求目標表(destTbl)不存在,因為在插入時會自動創建。

第二句(insert into select from)要求目標表(destTbl)存在,由於目標表已經存在,所以我們除了插入源表(srcTbl)的欄位外,還可以插入常量。

拓展資料:

結構化查詢語言(Structured Query Language)簡稱SQL,結構化查詢語言是一種資料庫查詢和程序設計語言,用於存取數據以及查詢、更新和管理關系資料庫系統。sql 語句就是對資料庫進行操作的一種語言。

常見語句:

1、更新:update table1 set field1=value1 where 范圍。

2、查找:select * from table1 where field1 like 』%value1%』 (所有包含『value1』這個模式的字元串)。

3、排序:select * from table1 order by field1,field2 [desc]。

4、求和:select sum(field1) as sumvalue from table1。

5、平均:select avg(field1) as avgvalue from table1。

6、最大:select max(field1) as maxvalue from table1。

7、最小:select min(field1) as minvalue from table1[searator]。

㈦ sql怎麼將一個表的數據插入到另一個表中

在HH中列出要插入列的列表跟select from mm表中的選擇的列的列表一一對應就可以了,當然兩邊的數據類型應該是兼容的。

1、insert into hh (fielda,fieldb,fieldc) select fieldx,fieldy,fieldz from mm

㈧ sql 資料庫如何向一張表內添加另一張表的數據後繼續添加數據

INSERT INTO A
SELECT a,b FROM B;
如果想增加c的值需要看你的記錄中c的值來源,如果是默認值可以在上面的select子句中直接加常數默認值,如是來源於別的表,可以把上面的查詢語句寫成一個連接語句。