Crear base de datos pubs ej. microsoft

Solo disponible en BuenasTareas
  • Páginas : 3 (521 palabras )
  • Descarga(s) : 0
  • Publicado : 9 de junio de 2011
Leer documento completo
Vista previa del texto
Como crear base de datos pubs: Insertar codigo en lineas de consulta SET NOCOUNT ON GO set nocount on set dateformat mdy USE master declare @dttm varchar(55) select@dttm=convert(varchar,getdate(),113) raiserror('Beginning InstPubs.SQL at %s ....',1,1,@dttm) with nowait GO if exists (select * from sysdatabases where name='pubs') begin raiserror('Dropping existing pubs database ....',0,1) DROPdatabase pubs end GO CHECKPOINT go raiserror('Creating pubs database....',0,1) go /* Use default size with autogrow */ CREATE DATABASE pubs GO CHECKPOINT GO USE pubs GO if db_name() 'pubs'raiserror('Error in InstPubs.SQL, ''USE pubs'' failed! Killing the SPID now.' ,22,127) with log GO

execute sp_dboption 'pubs' ,'trunc. log on chkpt.' ,'true' GO execute sp_addtype id ,'varchar(11)' ,'NOTNULL' execute sp_addtype tid ,'varchar(6)' ,'NOT NULL' execute sp_addtype empid ,'char(9)' ,'NOT NULL' raiserror('Now at the create table section ....',0,1) GO CREATE TABLE authors ( au_id id CHECK(au_id like '[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]') CONSTRAINT UPKCL_auidind PRIMARY KEY CLUSTERED, au_lname au_fname phone varchar(40) varchar(20) char(12) NOT NULL, NOT NULL, NOT NULLDEFAULT ('UNKNOWN'), address city state zip varchar(40) varchar(20) char(2) char(5) NULL, NULL, NULL, NULL

CHECK (zip like '[0-9][0-9][0-9][0-9][0-9]'), contract ) GO CREATE TABLE publishers (pub_id char(4) NOT NULL CONSTRAINT UPKCL_pubind PRIMARY KEY CLUSTERED CHECK (pub_id in ('1389', '0736', '0877', '1622', '1756') OR pub_id like '99[0-9][0-9]'), pub_name varchar(40) NULL, bit NOT NULL city state country

varchar(20) char(2) varchar(30)

NULL, NULL, NULL

DEFAULT('USA') ) GO CREATE TABLE titles ( title_id tid CONSTRAINT UPKCL_titleidind PRIMARY KEY CLUSTERED, title typevarchar(80) char(12) NOT NULL, NOT NULL

DEFAULT ('UNDECIDED'), pub_id char(4) NULL

REFERENCES publishers(pub_id), price money NULL, advance money NULL, royalty int NULL, ytd_sales int NULL, notes...
tracking img