Advertisement
Guest User

Untitled

a guest
May 5th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. CREATE DATABASE [aSchemaCheck]
  2. GO
  3.  
  4. USE [aSchemacheck]
  5. GO
  6. CREATE SCHEMA [Aschema] AUTHORIZATION [db_owner]
  7. GO
  8.  
  9. CREATE TABLE ASchema.Name
  10. (
  11. time time NOT NULL,
  12. Name char(10) NULL,
  13. )
  14. GO
  15.  
  16. CREATE SCHEMA [BSchema] AUTHORIZATION [db_owner]
  17. GO
  18.  
  19. CREATE TABLE BSchema.Name
  20. (
  21. time time NOT NULL,
  22. Name char(10) NULL,
  23. )
  24. GO
  25.  
  26. CREATE SCHEMA [CSchema] AUTHORIZATION [db_owner]
  27. GO
  28.  
  29. CREATE TABLE CSchema.Name
  30. (
  31. time time NOT NULL,
  32. Name char(10) NULL,
  33. )
  34. GO
  35.  
  36. $query = "INSERT INTO [$Schema].[Name]
  37. ([time]
  38. ,[Name])
  39. VALUES
  40. (CONVERT(time,GetDate())
  41. ,'AName')
  42. GO"
  43.  
  44. Invoke-Sqlcmd -ServerInstance $Server -Database $Database -Query $query
  45.  
  46. $Schemas = 'ASchema','BSchema','CSchema'
  47. foreach($Schema in $Schemas)
  48. {
  49. }
  50.  
  51. $srv = New-Object Microsoft.SqlServer.Management.Smo.Server $Server
  52. $db = $srv.Databases[$Database]
  53. $Schemas = $db.Schemas|Where-Object{$_.IsSystemObject -eq $false}|select Name -ExpandProperty Name
  54.  
  55. foreach($Schema in $Schemas)
  56. {
  57. }
  58.  
  59. $srv = New-Object Microsoft.SqlServer.Management.Smo.Server $Server
  60. $db = $srv.Databases[$Database]
  61. $Schemas = $db.Schemas|Where-Object{$_.IsSystemObject -eq $false}|Out-GridView -PassThru|select Name -ExpandProperty Name
  62.  
  63. foreach($Schema in $Schemas)
  64. {
  65. $query = "INSERT INTO [$Schema].[Name]
  66. ([time]
  67. ,[Name])
  68. VALUES
  69. (CONVERT(time,GetDate())
  70. ,'AName')
  71. GO"
  72.  
  73. Invoke-Sqlcmd -ServerInstance $Server -Database $Database -Query $query
  74. }
  75.  
  76. Invoke-Sqlcmd -ServerInstance $Server -Database $Database -InputFile $SQLFile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement