Creacion de tablas con valores predeterminados e indices

CREATE TABLE dbo.status_tabla
(
id int NOT NULL,
status_tabla nvarchar(50) NOT NULL
)  ON [PRIMARY]
GO
ALTER TABLE dbo.status_tabla ADD CONSTRAINT
PK_status_tabla PRIMARY KEY CLUSTERED
(
id
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
CREATE UNIQUE NONCLUSTERED INDEX IX_status_tabla ON dbo.status_tabla
(
status_tabla
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

Creacion de tablas, valores predeterminados e integridad referencial en SQL Server

CREATE TABLE dbo.presupuesto
(
id int NOT NULL,
idorden int NOT NULL,
fecha smalldatetime NOT NULL,
idusuario_captura int NOT NULL,
fechautoriza smalldatetime NULL,
idusuario_autoriza int NOT NULL,
importotal money NOT NULL,
idstatus_presupuesto int NOT NULL
)  ON [PRIMARY]
GO
ALTER TABLE dbo.presupuesto ADD CONSTRAINT
DF_presupuesto_fecha DEFAULT GETDATE() FOR fecha
GO
ALTER TABLE dbo.presupuesto ADD CONSTRAINT
DF_presupuesto_importotal DEFAULT 0 FOR importotal
GO
ALTER TABLE dbo.presupuesto ADD CONSTRAINT
DF_presupuesto_idstatus_presupuesto DEFAULT 0 FOR idstatus_presupuesto
GO
ALTER TABLE dbo.presupuesto ADD CONSTRAINT
PK_presupuesto PRIMARY KEY CLUSTERED
(
id
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
ALTER TABLE dbo.presupuesto ADD CONSTRAINT
fk_presupuesto_orden FOREIGN KEY
(
idorden
) REFERENCES dbo.orden
(
id
) ON UPDATE  NO ACTION
ON DELETE  NO ACTION

GO
ALTER TABLE dbo.presupuesto ADD CONSTRAINT
fk_presupuesto_usuario_captura FOREIGN KEY
(
idusuario_captura
) REFERENCES dbo.usuario
(
id
) ON UPDATE  NO ACTION
ON DELETE  NO ACTION

GO
ALTER TABLE dbo.presupuesto ADD CONSTRAINT
fk_presupuesto_usuario_autoriza FOREIGN KEY
(
idusuario_autoriza
) REFERENCES dbo.usuario
(
id
) ON UPDATE  NO ACTION
ON DELETE  NO ACTION

GO
ALTER TABLE dbo.presupuesto ADD CONSTRAINT
fk_presupuesto_status_presupuesto FOREIGN KEY
(
idstatus_presupuesto
) REFERENCES dbo.status_presupuesto
(
id
) ON UPDATE  NO ACTION
ON DELETE  NO ACTION

GO
ALTER TABLE dbo.presupuesto SET (LOCK_ESCALATION = TABLE)
GO

CREATE TABLE dbo.presupuestodet
(
id int NOT NULL,
numpar int NOT NULL,
idpresupuesto int NOT NULL,
cant float NOT NULL,
idproduc int NOT NULL,
idreparaclasif int NOT NULL,
idrepara int NOT NULL,
fechvigencia smalldatetime,
precio float NOT NULL,
impor float NOT NULL,
)  ON [PRIMARY]
GO
ALTER TABLE dbo.presupuestodet ADD CONSTRAINT
PK_status_presupuesto PRIMARY KEY CLUSTERED
(
id
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
ALTER TABLE dbo.presupuestodet ADD CONSTRAINT
DF_presupuestodet_cant DEFAULT 0 FOR cant
GO
ALTER TABLE dbo.presupuestodet ADD CONSTRAINT
DF_presupuestodet_idproduc DEFAULT 0 FOR idproduc
GO
ALTER TABLE dbo.presupuestodet ADD CONSTRAINT
DF_presupuestodet_idreparaclasif DEFAULT 0 FOR idreparaclasif
GO
ALTER TABLE dbo.presupuestodet ADD CONSTRAINT
DF_presupuestodet_idrepara DEFAULT 0 FOR idrepara
GO
ALTER TABLE dbo.presupuestodet ADD CONSTRAINT
DF_presupuestodet_fechvigencia DEFAULT GETDATE() FOR fechvigencia
GO
ALTER TABLE dbo.presupuestodet ADD CONSTRAINT
DF_presupuestodet_precio DEFAULT 0 FOR precio
GO
ALTER TABLE dbo.presupuestodet ADD CONSTRAINT
DF_presupuestodet_impor DEFAULT 0 FOR impor
GO

ALTER TABLE dbo.presupuestodet ADD CONSTRAINT
fk_presupuestodet_presupuesto FOREIGN KEY
(
idpresupuesto
) REFERENCES dbo.presupuesto
(
id
) ON UPDATE  NO ACTION
ON DELETE  NO ACTION

GO
ALTER TABLE dbo.presupuestodet ADD CONSTRAINT
fk_presupuestodet_produc FOREIGN KEY
(
idproduc
) REFERENCES dbo.produc
(
id
) ON UPDATE  NO ACTION
ON DELETE  NO ACTION

GO
ALTER TABLE dbo.presupuestodet ADD CONSTRAINT
fk_presupuestodet_reparaclasif FOREIGN KEY
(
idreparaclasif
) REFERENCES dbo.reparaclasif
(
id
) ON UPDATE  NO ACTION
ON DELETE  NO ACTION

GO
ALTER TABLE dbo.presupuestodet ADD CONSTRAINT
fk_presupuestodet_repara FOREIGN KEY
(
idrepara
) REFERENCES dbo.repara
(
id
) ON UPDATE  NO ACTION
ON DELETE  NO ACTION

GO

Firewall Rule for Sql Server 2008 on Windows 7

Para permitir el acceso a SQL Server mediante la intranet realizar lo siguiente:

Entrar al grupo de programas Microsoft SQL Server 2008 R2 -> Herramientas de configuración -> Administrador de configuración de SQL Server y en la seccion de Configuracion de red de la instancia de SQL Server Habilitar el protocolo TCP/IP

Posteriormente proceder con las siguientes indicaciones para la configuración del Firewall de Windows

Open the Control Panel

  1. Click “System and Security” if you are in “Category” view mode.
  2. Click “Windows Firewall”. (The green text)
  3. Click “Advanced settings” along the left hand side.
  4. Click “Inbound Rules” along the left hand side.
  5. Click “New Rule…” to the right in the actions pane.
  6. Ensure “Program” is selected and click “Next >”
  7. Select “This program path:” radio button and click browse.
  8. You need to select the sqlservr.exe file which for my 2005 instance was located “C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLBinn”
  9. Click “Open”
  10. Click “Next >”
  11. Click “Next >” again
  12. Click “Next >” again
  13. Give it a name of “Sql Server 2008 R2” or another appropriate name. I would suggest giving the service name maybe. I Called it this “Sql Server: Sql2005“
  14. Click “Finish”

You may need to also add the Sql Browser service so that any named instances can be found.

  1. Click “New Rule…” again in the actions pane.
  2. Select “Port” and click “Next >”
  3. Select “UDP”
  4. Select “Specific local ports” and enter the port number 1434
  5. Click “Next >”
  6. Click “Next >” again
  7. Click “Next >” again
  8. Enter a name like : “Sql Server Browser”

How to: Stop an Instance of SQL Server (net Commands)

To stop the default instance of SQL Server

  1. From a command prompt, enter one of the following commands:

    net stop "SQL Server (MSSQLSERVER)"

    -or-

    net stop MSSQLSERVER

 To stop a named instance of SQL Server

  1. From a command prompt, enter one of the following commands. Replace instancename with the name of the instance you want to manage.

    net stop "SQL Server ( instancename )"

    -or-

    net stop MSSQL$ instancename

ms190236.note(en-us,SQL.100).gifNote:
Stopping an instance of SQL Server with the net stop command causes SQL Server to perform a checkpoint in all databases, saving all changed data to disk.

http://technet.microsoft.com/en-us/library/ms190236.aspx