Advertisement
hoscanoa

Esquema de Base de Datos

Mar 12th, 2014
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.86 KB | None | 0 0
  1. USE MASTER
  2. GO
  3.  
  4. CREATE DATABASE MyBD060314
  5. GO
  6.  
  7. USE MyBD060314
  8. GO
  9.  
  10. --CREEMOS LOS SCHEMES
  11.  
  12. CREATE SCHEMA SCHRRHH
  13. GO
  14.  
  15. CREATE SCHEMA SCHSales
  16. GO
  17.  
  18. CREATE SCHEMA SCHProduction
  19. GO
  20.  
  21. CREATE SCHEMA SCHCompras
  22. GO
  23.  
  24.  
  25. --VER SCHEMAS
  26.  
  27. SELECT * FROM SYS.schemas
  28. GO
  29.  
  30.  
  31. --CREANDO TABLAx
  32.  
  33. CREATE TABLE TXXX
  34. (
  35.     campo1 CHAR(5),
  36.     campo2 VARCHAR(20),
  37. )
  38. GO
  39.  
  40. --CREANDO TABLAS EN ESQUEMAS DEFINIDOS
  41. CREATE TABLE SCHSales.TBCLIENTE
  42. (
  43.     cli_id INT,
  44.     cli_nom VARCHAR(30),
  45.     cli_dir VARCHAR(30),
  46.     cli_tel VARCHAR(30),
  47.     cli_monto MONEY
  48. )
  49. --ON SCPCLIENTE(cli_monto)
  50. GO
  51.  
  52.  
  53. CREATE TABLE SCHRRHH.TBPERSONAL
  54. (
  55.     per_id INT IDENTITY(1001,1),
  56.     per_nom VARCHAR(30),
  57.     per_ap VARCHAR(30),
  58.     per_fna DATE,
  59.     per_sue MONEY
  60. )
  61. GO
  62.  
  63. CREATE TABLE SCHCompras.TBPROVEEDOR
  64. (
  65.     prv_id INT IDENTITY,
  66.     prv_rzn VARCHAR(30),
  67.     prv_dir VARCHAR(30),
  68.     prv_cont VARCHAR(30)
  69. )
  70. GO
  71.  
  72. CREATE TABLE SCHProduction.TBPRODUCTO
  73. (
  74.     pro_id CHAR(8) NOT NULL,
  75.     pro_desc VARCHAR(30),
  76.     pro_marca VARCHAR(30),
  77.     pro_precio MONEY
  78. )
  79. GO
  80.  
  81.  
  82.  
  83. /*-----------------------------------------------*/
  84.  
  85. /******************CREACION DE LOGIN************/
  86.  
  87. CREATE LOGIN LgMaggie
  88. WITH PASSWORD = '123'
  89. GO
  90.  
  91. /****************CREACION DE USUARIOS***********/
  92. CREATE USER usrMaggie
  93. FOR LOGIN LgMaggie
  94. WITH DEFAULT_SCHEMA = [SCHSales]
  95. GO
  96.  
  97. /*AUTORIZANDO EL USO DEL SCHEMA Y SUS OBJETOS AL USUARIO*/
  98. ALTER AUTHORIZATION ON SCHEMA::[SCHSales] TO [usrMaggie]
  99. GO
  100.  
  101.  
  102. /*
  103. Volver a logeoar y notar que solo se muestra los esquemas
  104. autorizados
  105. */
  106.  
  107. /*********************************************/
  108. CREATE LOGIN LgJavier
  109. WITH PASSWORD ='abc'
  110. GO
  111.  
  112. CREATE USER usrJavier
  113. FOR LOGIN LgJavier
  114. WITH DEFAULT_SCHEMA =[SCHRRHH]
  115. GO
  116.  
  117. ALTER AUTHORIZATION ON SCHEMA::[SCHRRHH] TO [usrJavier]
  118. GO
  119.  
  120.  
  121. /*********************************************/
  122. CREATE LOGIN LgHernan
  123. WITH PASSWORD ='abc'
  124. GO
  125.  
  126. CREATE USER usrHernan
  127. FOR LOGIN LgHernan
  128. WITH DEFAULT_SCHEMA =[SCHProduction]
  129. GO
  130.  
  131. ALTER AUTHORIZATION ON SCHEMA::[SCHProduction] TO [usrHernan]
  132. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement