असल में मुझे सभी तालिकाओं के लिए मूल रूप से पहचान वृद्धि को रीसेट करने की आवश्यकता है। यहां मैंने कुछ कोड की कोशिश की, लेकिन यह विफल हो गया।एसक्यूएल सर्वर सभी तालिकाओं के लिए पहचान वृद्धि रीसेट करें
लिंक से वास्तविक कोड:
USE World00_Character
GO
-- Create a cursor to loop through the System Ojects and get each table name
DECLARE TBL_CURSOR CURSOR
-- Declare the SQL Statement to cursor through
FOR (SELECT Name FROM Sysobjects WHERE Type='U')
-- Declare the @SQL Variable which will hold our dynamic sql
DECLARE @SQL NVARCHAR(MAX);
SET @SQL = '';
-- Declare the @TblName Variable which will hold the name of the current table
DECLARE @TblName NVARCHAR(MAX);
-- Open the Cursor
OPEN TBL_CURSOR
-- Setup the Fetch While that will loop through our cursor and set @TblName
FETCH NEXT FROM TBL_CURSOR INTO @TblName
-- Do this while we are not at the end of the record set
WHILE (@@FETCH_STATUS <> -1)
BEGIN
-- Appeand this table's select count statement to our sql variable
SET @SQL = @SQL + ' (SELECT '''[email protected]+''' AS Table_Name,COUNT(*) AS Count FROM '[email protected]+') UNION';
-- Delete info
EXEC('DBCC CHECKIDENT ('[email protected]+',RESEED,(SELECT IDENT_SEED('[email protected]+')))');
-- Pull the next record
FETCH NEXT FROM TBL_CURSOR INTO @TblName
-- End the Cursor Loop
END
-- Close and Clean Up the Cursor
CLOSE TBL_CURSOR
DEALLOCATE TBL_CURSOR
-- Since we were adding the UNION at the end of each part, the last query will have
-- an extra UNION. Lets trim it off.
SET @SQL = LEFT(@SQL,LEN(@SQL)-6);
-- Lets do an Order By. You can pick between Count and Table Name by picking which
-- line to execute below.
SET @SQL = @SQL + ' ORDER BY Count';
--SET @SQL = @SQL + ' ORDER BY Table_Name';
-- Now that our Dynamic SQL statement is ready, lets execute it.
EXEC (@SQL);
GO
त्रुटि संदेश:
Error: Msg 102, Level 15, State 1, Line 1 Incorrect syntax near '('.
मैं कैसे या तो ठीक है कि SQL या अपने मूल करने के लिए सभी तालिकाओं के लिए पहचान रीसेट कर सकते हैं?
धन्यवाद
खैर के साथ 1. 10001 के साथ 50 और एक अन्य तो जैसे 50 80 डिफ़ॉल्ट बीज 101 के साथ टेबल और की तरह तो मैं एसक्यूएल में थोड़े पाश करने की कोशिश की मैं है, लेकिन पीएचपी जो आसान हो सकता है के साथ पाश कर की कोशिश करेंगे । – DanSpd
@DanSpd: ऐसा करने के अपने अंतिम और बिल्कुल सही तरीके से मेरा जवाब अपडेट किया गया! :-) का आनंद लें। –
बहुत बहुत धन्यवाद।मेरा काम आसान तरीका बनाता है :) आपसे प्यार करते हैं – DanSpd