1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#Realizado por Santiago Candamil [void][System.Reflection.Assembly]::LoadWithPartialName("MySql.Data") $Connection = New-Object MySql.Data.MySqlClient.MySqlConnection $ConnectionString = "server=" + "localhost" + ";port=3306;uid=" + "root" + ";pwd=" + ";database="+"libreria" $Connection.ConnectionString = $ConnectionString $Connection.Open() $Query = 'create table autor(IDautor int auto_increment primary key, nombre varchar(50), apellidos varchar(60), nacionalidad varchar (30), fechanacimiento date)' $Command = New-Object MySql.Data.MySqlClient.MySqlCommand($Query, $Connection) $DataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($Command) $DataSet = New-Object System.Data.DataSet $RecordCount = $dataAdapter.Fill($dataSet, "data") $DataSet.Tables[0] $Query1 = 'create table editorial(nombreeditorial varchar (50) not null, CIFeditorial char (13) primary key)' $Command = New-Object MySql.Data.MySqlClient.MySqlCommand($Query1, $Connection) $DataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($Command) $DataSet = New-Object System.Data.DataSet $RecordCount = $dataAdapter.Fill($dataSet, "data") $DataSet.Tables[0] $Query2 = 'create table libro(ISBN char(13) primary key, titulo varchar(100), precio decimal(5,2) null, nejemplares int null default 1, añoedicion int unsigned, IDautor int(11) null, CIFeditorial char(13) not null, foreign key(IDautor) references autor(IDautor), foreign key(CIFeditorial) references editorial(CIFeditorial) on delete restrict on update cascade)' $Command = New-Object MySql.Data.MySqlClient.MySqlCommand($Query2, $Connection) $DataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($Command) $DataSet = New-Object System.Data.DataSet $RecordCount = $dataAdapter.Fill($dataSet, "data") $DataSet.Tables[0] $Connection.Close() |