當前位置:首頁 » 編程語言 » sql將數據由低到高
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql將數據由低到高

發布時間: 2022-11-22 12:35:57

sql server 怎麼將低版本的資料庫附加到高版本

您好:
SQL Server向下兼容的。
直接附加就好啦。

⑵ sas中sql中的優先順序

sql執行順序優先順序由高到低依次是:from關鍵字後面的語句、where關鍵字後面的語句、「group by」後面的語句、select後面的語句、「order by」後面的語句。

php入門到就業線上直播課:進入學習

這一條語句包含我們經常用到的一些關鍵字,select,from,where,group by,order by,它的執行順序如下:
先執行from關鍵字後面的語句,明確數據的來源,它是從哪張表取來的。
接著執行where關鍵字後面的語句,對數據進行篩選。
再接著執行group by後面的語句,對數據進行分組分類。
然後執行select後面的語句,也就是對處理好的數據,具體要取哪一部分。
最後執行order by後面的語句,對最終的結果進行排序。

⑶ 如何把SQL Server資料庫從高版本降級到低版本

直接給SQL Server資料庫降級是不支持的。但您可以使用一個靈活的變通方法來解決這個問題。您可以使用SQL Server Management Studio中首先為一個較低的版本生成資料庫腳本,然後使用數據導入/導出向導將原來資料庫數據傳輸到高版本資料庫中。例如,如果你想降低一個SQL Server 2008資料庫到SQL Server 2005,您可以按照以下步驟:
1. 在SQL Server Management Studio 2008中打開SQL Server2008資料庫。
2.在對象資源管理器中右鍵單擊資料庫名稱並選擇「任務生成腳本......」
3.在「腳本向導」對話框中,選擇資料庫的名稱,並檢查「腳本所有在選擇資料庫對象」。然後點擊「下一步」。
4.設置為SQL Server2005的伺服器版本的腳本「選項」。
5. SQL Server 2005中運行腳本。
6. 使用SQL Server導入和導出向導從SQL Server 2008到SQL Server 2005導入數據
同樣,如果你想降低一個SQL Server 2005資料庫到SQL Server 2000,你也可以在SQL Server 2005 Management Studio中執行上述步驟。

⑷ 低版本的mysql資料庫表文件如何導入到高版本的mysql文件中

低版本的mysql資料庫表文件如何導入到高版本的mysql文件中
mysqlmp可以導出純sql文本,但是有些建表語句的參數名在高低版本中是不一樣的,

比如說在mysql4.*中的引擎指定用type,而mysql5.5的時候就用engine,
可以先把備份的sql文件先導到5.0左右的,會有警告,但是能導成功,然後再從5.0中導出sql文件,最後遷移到5.5的

建議是在數據遷移的時候版本差距別太大,有可能會出現版本兼容問題。

⑸ SQL的數據文件能否從低版本掛接到高版本上

不能,sqlserver2000的版本要比7.0高。

⑹ 如何把SQL Server資料庫從高版本降級到低版本

由於目前還廣泛使用著SQLServer2000,很多公司又想使用新的SQLServer,從而直接【分離/附加】或者【備份/還原】資料庫,在
不同版本之間存放。往往就會遇到版本不兼容的問題。前幾天遇到了從我本機2008R2上備份的一個資料庫還原到2008上面時報錯:

運行版本10.50.2500(2008R2是10.50)和10.00.1600(2008是10.00)中可以看出這個版本不兼容問題,大部分情況
下,從低版本升級到高版本,只要不是跨度太大,如2000升級到2012,都不會怎麼報錯。除非使用了一些新版本不兼容的特性如*=來實現left
join的語句。但是就像上圖那樣,從高版本還原到低版本的時候,問題就出現了,而且幾乎一定會報錯。
下面給出幾個小建議,例子是從2008 降級到2005:
方法一:使用圖形化操作(GUI),打開SSMS(SQL Server Management Studio)

步驟1:右鍵你要降級的資料庫,按下圖選擇:

步驟2:在對話框中選擇:

步驟3:在【高級】中選擇下圖:

步驟4:把腳本保存起來,然後在SQLServer2005中運行腳本。
詳細步驟可以看: 中的13樓的回復,有截圖
步驟5:通過【任務】→【導入數據】,把數據從2008導入到使用腳本創建的庫上如下圖,就完成了:

方法二:使用系統自帶的存儲過程實現:sp_dbcmptlevel ——將某些資料庫行為設置為與指定的 SQL Server 版本兼容
下面是其內部實現代碼:

[sql] view plain print?
SET QUOTED_IDENTIFIER ON
SET ANSI_NULLS ON
GO
create procere sys.sp_dbcmptlevel -- 1997/04/15
@dbname sysname = NULL, -- database name to change
@new_cmptlevel tinyint = NULL OUTPUT -- the new compatibility level to change to
as
set nocount on

declare @exec_stmt nvarchar(max)
declare @returncode int
declare @comptlevel float(8)
declare @dbid int -- dbid of the database
declare @dbsid varbinary(85) -- id of the owner of the database
declare @orig_cmptlevel tinyint -- original compatibility level
declare @input_cmptlevel tinyint -- compatibility level passed in by user
,@cmptlvl80 tinyint -- compatibility to SQL Server Version 8.0
,@cmptlvl90 tinyint -- compatibility to SQL Server Version 9.0
,@cmptlvl100 tinyint -- compatibility to SQL Server Version 10.0
select @cmptlvl80 = 80,
@cmptlvl90 = 90,
@cmptlvl100 = 100

-- SP MUST BE CALLED AT ADHOC LEVEL --
if (@@nestlevel > 1)
begin
raiserror(15432,-1,-1,'sys.sp_dbcmptlevel')
return (1)
end

-- If no @dbname given, just list the valid compatibility level values.
if @dbname is null
begin
raiserror (15048, -1, -1, @cmptlvl80, @cmptlvl90, @cmptlvl100)
return (0)
end

-- Verify the database name and get info
select @dbid = dbid, @dbsid = sid ,@orig_cmptlevel = cmptlevel
from master.dbo.sysdatabases
where name = @dbname

-- If @dbname not found, say so and list the databases.
if @dbid is null
begin
raiserror(15010,-1,-1,@dbname)
print ' '
select name as 'Available databases:'
from master.dbo.sysdatabases
return (1)
end

-- Now save the input compatibility level and initialize the return clevel
-- to be the current clevel
select @input_cmptlevel = @new_cmptlevel
select @new_cmptlevel = @orig_cmptlevel

-- If no clevel was supplied, display and output current level.
if @input_cmptlevel is null
begin
raiserror(15054, -1, -1, @orig_cmptlevel)
return(0)
end

-- If invalid clevel given, print usage and return error code
-- 'usage: sp_dbcmptlevel [dbname [, compatibilitylevel]]'
if @input_cmptlevel not in (@cmptlvl80, @cmptlvl90, @cmptlvl100)
begin
raiserror(15416, -1, -1)
print ' '
raiserror (15048, -1, -1, @cmptlvl80, @cmptlvl90, @cmptlvl100)
return (1)
end

-- Only the SA or the dbo of @dbname can execute the update part
-- of this procere sys.so check.
if (not (is_srvrolemember('sysadmin') = 1)) and suser_sid() <> @dbsid
-- ALSO ALLOW db_owner ONLY IF DB REQUESTED IS CURRENT DB
and (@dbid <> db_id() or is_member('db_owner') <> 1)
begin
raiserror(15418,-1,-1)
return (1)
end

-- If we're in a transaction, disallow this since it might make recovery impossible.
set implicit_transactions off
if @@trancount > 0
begin
raiserror(15002,-1,-1,'sys.sp_dbcmptlevel')
return (1)
end

set @exec_stmt = 'ALTER DATABASE ' + quotename(@dbname, '[') + ' SET COMPATIBILITY_LEVEL = ' + cast(@input_cmptlevel as nvarchar(128))

-- Note: database @dbname may not exist anymore
exec(@exec_stmt)

select @new_cmptlevel = @input_cmptlevel

return (0) -- sp_dbcmptlevel
GO

語法

[sql] view plain print?
sp_dbcmptlevel [ [ @dbname = ] name ]
[ , [ @new_cmptlevel = ] version ]

參數
[ @dbname = ] name
要為其更改兼容級別的資料庫的名稱。資料庫名稱必須符合標識符的規則。name 的數據類型為 sysname,默認值為 NULL。
[ @new_cmptlevel = ] version
資料庫要與之兼容的 SQL Server 的版本。version 的數據類型為 tinyint,默認值為 NULL。該值必須為下列值之一:
80 = SQL Server 2000
90 = SQL Server 2005
100 = SQL Server 2008
返回代碼值
0(成功)或 1(失敗)

注意事項:
後續版本的 Microsoft SQL Server 將刪除該功能。請不要在新的開發工作中使用該功能,並盡快修改當前還在使用該功能的應用程序。 改為使用 ALTER DATABASE 兼容級別。

⑺ 怎樣用SQL語句按日期進行從高到低進行排序

用SQL語句按日期進行從高到低進行排序:select * from tmp order by time desc;

⑻ 寫一個sql 查詢一個表中姓名相同的記錄,並把數據按照重復的次數從高到低排列顯示

select姓名列,count(1)as[重復次數]from表名groupby姓名列havingcount(1)>=2orderby重復次數desc

⑼ SQL低版本備份的資料庫如何恢復到高版本的資料庫

好像也沒啥好的辦法,自帶的不行。你可以考慮帶數據帶結構一起導出腳本,然後在目標機上執行腳本就相當於備份還原了。